Friday 5 May 2017

ACCESSING THE MEMBERS OF A STRUCTURE in C Language

Individual structure members can be used like other variables of the same type. Structure members are accessed using the structure member operator (.), also called the dot operator, between the structure name and the member name. The syntax for accessing the member of the structure is:
structurevariable. member-name;

Let us take the example of the coordinate structure.
struct coordinate{
int x;
int y;
};

Thus, to have the structure named first refer to a screen location that has coordinates x=50, y=100, you could write as,
first.x = 50;
first.y = 100;

To display the screen locations stored in the structure second, you could write,
printf ("%d,%d", second.x, second.y);
The individual members of the structure behave like ordinary date elements and can be accessed accordingly.
Now let us see the following program to clarify our concepts. For example, let us see, how will we go about storing and retrieving values of the individual data members of the student structure.
Visit our site for Registration c language coaching in jaipur

0 comments:

Post a Comment