1. Structure is capable of holding heterogenous data.i.e data of different types are grouped together under single name called structure.
2. Structure tmplete doesnot reserver any space in memory for members..Space reserved only when structure variable is declared.
Struct nagendra {
int marks;
char subject[];
} //here structure variable is not declared...so no space is reserved in memory for this structure.
Struct nagendra {
int marks;
char subject[];
}variable1; //variable is declared so memory will be reserved for structure
3. Members names inside structure should be different from each other but it can be similar to ny other variables outside the stucture
4. Structure variables can be defines in 2 ways
a. struct student{
char name[22];
int rollno;
float marks; //with structure definition
}stu1,stu2,stu3;
b. struct student{
char name[22];
int rollno;
float marks; //using stucture Tag
};
struct student stu1,stu2;
struct student stu3;
5. Compiler will reserve enough space for each variables(stu1,stu2,stu3) that is sufficient to hold all the members.For example each variable in above example of type struct student will occupy (22+4+4)bytes.
6. Initializing of members inside the structure is not possible.
Ex: struct student{
char[22]="nagendra"; //Invalid
int marks=10; //Invalid
}
7. In structures leaving variable initilizer blank,then by default it initializes to values of 0..Lets represent it as follows.
struct student stu1={"nagendra"}; this is equivalent to struct student stu1={"nagendra",0,0};
8. Members of structures are stored in consecutive memory locations.
0 comments:
Post a Comment