Structure in C

As the array is used to make variables of the same data type and can be accessed by the same name but different index. The structure is used to make variables which have different variables of different data types (which are called structure members).

Let us understand by an example. Ex1 is showing an array and Ex2 is showing structure.

Ex1. int arr[3];

This can be represented by

The below example is about structure. The syntax of structure is explained in the next topic but just for now let us understand that below structure’s name is str. It has 4 members : a,f,c,b. And all of these members are of different data types.

struct str{
int a;
float f;
char c;
int b[3];

The above diagram shows that str has members a,f,c,b. b is an array so it has 3 array elements b[0], b[1], b[3]. So we can say that a structure can have an array also. It can have any other data types like a pointer, substructure (structure inside a structure).

Lesson learned from this blog:

1) Use of structure.
2) Difference between use of array and structure.
3) Example of array and structure declaration.
4) What is the member variable of structure?
5) Why we can not use an array instead of a structure for multiple data types.

Notify of
Inline Feedbacks
View all comments