A structure is a user-defined compound data type which consists of data members related to a person or an item. It is referred to record in other programming languages.
|
Note : The structure definition ends with a semicolon ( ; ) after the closing brace.
|
Structure variables can be declared using the tag-name of the structure along with the keyword struct.
|
It declares structure variables x, y and z and an array std with 50 elements.
Dot (.) or period operator is used to access a data member in a structure variable or an array element. It has the following form :
structure_variables.data_member
Note : That the dot operator separates the structure variables or array and the data member.
x.roll_no
- std[i].roll_no
x.sname
- std[i].sname
x.total
- std[i].total
sizeof() of a structure is equal to the total number of bytes occupied in RAM by various data members in the structure.
|
The size of this structure is equal to 24bytes ( 2bytes for int + 20bytes for char + 2bytes for int ). The sizeof() function is written as follows to print the size of the structure :
printf("%d",sizeof(struct student));
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.