Data structure is the way you organize data in the main memory during execution of a program.
An array is a collection of similar data elements.
Declaration : int A[5];
Initialization : int B[5]={2,4,6,8,10};
If you have an array of some size and don't define the elements they will become zero by default.
A structure is a collection of data members that are related under one name.
- Defining a structure
struct Rectangle { int length; int width; };
- Size of a structure
The total size of a structure is the sum of its element in memory. An int is 4 bytes.
- Declaring a structure
struct Rectangle r;
struct Rectangle r={10,15}
with initialization
- Accessing members
Members are accessed with dot operators.
r.length = 15;
r.width = 10;