Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Difference between structures and arrays

Status
Not open for further replies.

navenmou

Full Member level 4
Joined
Sep 25, 2010
Messages
228
Helped
49
Reputation
98
Reaction score
46
Trophy points
1,318
Location
Bangalore, India
Activity points
2,588
Hi all

Greetings for good day.....

What is difference between structures and arrays when we use in same data type in structures
struct name
{
int a;
int b;
int c;
}

int a[3];

what is difference between above two declarations....
 

Hi;
In structures you can use different types such as strings and chars. And reach each of them independently.
ie;
struct student {
char *name[10];
char *surname[15];
int number;
};
struct student s1;
...
s1.name, s1.number etc.

On the other hand structs are used to build complicated data structures like stack, linklist and so on... Each elemant may have a pointer (in the same struct type) to the next element. So that they are connected each other and so on...

That's what i have know about.
Hope helps...
 

A structure is a collection of one or more variables, possibly of different data types... Array has same data type.

To copy structure content into another structure is easy
a=b;

In arrays "for" is mandatory for copy (memset is possible).

Enjoy
 
Last edited:

Thanks for giving your valuables replies...i know structure can contain one or more data types variables....but here my doubt is is we have same data type variables in structure then which one is better structure or array...here code like this

struct name {
int a, b,c;
}
int a[3];

In structure we are three variables with same data type..In array also we taking three elements..Now which one is better??
 

In structure we are three variables with same data type..In array also we taking three elements..Now which one is better??

Structurally, no pun intended, their storage in memory is the same.

The major difference is the array offers the convenience of pointer arithmetic or array subscripts such as *(a + i) or a respectfully. These techniques are available due to the fact the elements of an array must be of the same type and are defined during the arrays definition.

The elements of a structure cannot be accessed in a similar manner due to the fact the contents of a structure can be composed of many different types. Therefore, elements of a structure must be accessed using either the "." (dot) operator or in the case of a pointer to a structure the "->" operator.

If the data element types are homogenous, then the array is usually the preferred method of storage type, as the pointer arithmetic and array subscripts makes sequential access to elements of the array relatively easy in loops.

If the data elements are of varying types then a structure must be used as the storage type.

BigDog
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top