What is Structure?
The struct is predefined keyword which work is to make user defined variable. you can make own variable with the help of struct keyword. This is like array but the difference is that the array that can hold several data item with similar type and in case of structure that can hold several data item with different type( int, float, character).
struct <structure name>
{
data-type variable name;
data-type variable name;
data-type variable name;
};
struct is keyword. structure name may be your choice. the main thing is that it is compulsory to write semicolon end of closed curly bracket.
struct book
{
char name ;
float price ;
int pages ;
} ;
now you can see the book is name of structure. we use three different variable name char, float and int type. The size of int is 2, the char is 1 and float is 4 bytes. The total size is 7 bytes.
what is book?
The book is type of variable like char, int and float. The book type is struct type. now we create variable of type book.
struct book b1,b2,b3;
you can choose your own choice name. It is compulsory to write struct keyword in the time of declaration. what will be the size of b1 variable. The size of variable b1 is 7 bytes.
Comments
Post a Comment