Thursday, 2 February 2012

What is a structure? How does a structure differ from an array?

           Structure is the collection of different data types. It allocates memory for the highest data items. We can access more than one element at a time of all items. We can access the elements of structure by using dot (.) operator in case of normal variable or by using (→) arrow operator in case of pointer.

//Demonstration of structure
struct student
char name[10];
int rall;
float age;
struct student s;
printf("Enter the name, rall no., and age of a student ");
It does not allocate memory till the elements of the structure are access.
It allocates memory only for the elements of the subscripts.
It allocates the memory for the highest data type.
It allocates memory of same files that is if we declare integer type array then it allocates 2v byte memory for each cell.
It contain array within itself.
It does not contain structure within itself.
It can contain only non-homogeneous data types.
It can contain only homogeneous data types.
The elements of structure are accessed by using dot (.) operator with structure reference name.
We can access the array by using index number.

No comments:

Post a Comment