Prev Next
C Structure is a collection of different data types which are grouped together and each element in a C structure is called member.
- If you want to access structure members in C, structure variable should be declared.
- Many structure variables can be declared for same structure and memory will be allocated for each separately.
- It is a best practice to initialize a structure to null while declaring, if we don’t assign any values to structure members.
……
Difference between C variable, C array and C structure:
- A normal C variable can hold only one data of one data type at a time.
- An array can hold group of data of same data type.
- A structure can hold group of data of different data types
- Data types can be int, char, float, double and long double etc.
Datatype |
C variable |
C array |
C structure |
|||
Syntax | Example | Syntax | Example | Syntax | Example | |
int | int a | a = 20 | int a[3] | a[0] = 10 a[1] = 20 a[2] = 30 a[3] = ‘ |