II-270 Programming Concepts
4. How to declare structure variables?
Ans: The structure variables can be declared by including variable names between the closing brace and
the terminating semicolon in the structure definition. This can be followed from the following example.
In the above example, the bk1 and bk2 are the variables of type struct book.
Alternately, one can also declare the structure variables as per the following example.
struct book bk1,bk2;
In the above example bk1,bk2 are the structure variables of type struct book.
5. When is memory allocated to a structure members?
Ans: Memory is not allocated/reserved when the structure is defined. Structure definition describes
the template. Memory is allocated only after declaration of variables of the corresponding type.
For example, in the following example, memory is not reserved when structure is declared.
int pages ;
float price ;
After declaring, the variables of structure memory are allocated.
After writing the above code, one can write the following code:
struct book1 bk1;
The bk1 is the variable and now memory is allocated to the members of structure book1.
6. Explain the use of the dot operator.
Ans: The dot (.) operator accesses the structure members.
For example, structure_variable.member or bk1.book
M13_ITL-ESL4791_02_SE_C13.indd 270 12/22/2012 5:06:14 PM