Powered by Blogger.

Difference Between Array and Structure



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.

Difference Between Array and Structure

  • 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 {
  unsigned int f1:10;
  unsigned int f2:1;
  unsigned int f3:80;
};
I hope these difference are helpful for you. For detail information you can visit our website:  



facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09