Difference Between Array and Structure
The main difference between array and structure is; array is collection of similar data type but structure can store different datatype.
- Array allocates static memory and uses index / subscript for accessing elements of the array. Structures allocate dynamic memory and uses (.) operator for accessing the member of a structure.
- Array is a pointer to the first element of it. Structure is not a pointer
- Array element access takes less time in comparison with structures.
Well, for starters an array is a collection of homogeneous items ... like an array of ints, chars, etc. But a structure can be a collection of heterogeneous items like ...
struct A {
int item_1;
char* item_2;
double item_3;
};
And once you have defined a struct you cannot add more items to it.
But with arrays, you can add more items by dynamic allocation using realloc, malloc, dealloc, etc.
One plus point about structs you can define bit fields, e.g.
struct packed_struct {I hope these difference are helpful for you. For detail information you can visit our website:
unsigned int f1:10;
unsigned int f2:1;
unsigned int f3:80;
};
No comments :
Post a Comment