Structure in
-> A Structure can be defined as a collection of data member that are related under one name and those member can be of similar type or dissimilar name.
-> Simply, it is called as grouping of data items.
-> It is used for defining user defied data-type. By using primitive data-type(int,float….).
-> Skeleton :
struct Rectangle { int length; // 2 byte(size) int breadth; //2 byte(size) // ---------------------------------- }; // 4 byte (total size of this structure) int main() { struct Rectangle r; //declaration of structure struct Rectangle r={10,5}; //declaration+initialization of structure }
Note: Structure occupy memory when we create a variable of structure not when we declare of structure.
How to access the member of the structure ?
-> By using dot(.) operator.
r.length=15; //for above structure example accessing length of rectangle.
r.breadth=10;