Differentiate between array and structures in C

CServer Side ProgrammingProgramming

The major differences between an array and a structure in C programming language are as follows −

ArraysStructures
An array is a single entity representing a collection of data items of same data types.
A structure is a single entity representing a collection of data items of different data types.
Individual entries in an array are called elements.
Individual entries in a structure are called members.
An array declaration reserves enough memory space for its elements.
The structure definition reserves enough memory space for its members.
There is no keyword to represent arrays but the square braces [] preceding the variable name tells us that we are dealing with arrays.
The keyword struct tells us that we can deal with structures.
Initialization of elements can be done during array declaration.
Initialization of members can be done only during structure definition.
The elements of an array are stored in sequence of memory locations.
The members of a structure are not stored in sequence of memory locations.
The array elements are accessed and followed by the square braces [] within which the index is placed.
The members of a structure are accessed by the dot operator.
Its general format is data type variablename [size];
Its general format is as follows −
struct <struct name>{
data_type structure member 1;
data_type structure member 2;
•
•
•
data_type structure member N;
} structure variable;
For example,


int sum (100);


For example,


struct student{
char studname (25);
int rollno;
} stud1;


raja
Published on 02-Sep-2021 13:16:22

Advertisements