Thursday, April 10, 2008

Stinking Structures

What is Structure?

Is it 36-26-36…

No, it is something different. Array is a collection of different types, but structure is collection of different data types.

Technically speaking Structure is allocates more memory.

Struct {

Int a,

Char c,

Float d,

};

It stores 2+1+4=7 bytes in memory. But if we use union we can reduce the memory space to 4 bytes.

Union allocate memory for the largest data i.e. here float size is 4 bytes so it allocates4 bytes.

Can Structure be declared within a structure?

Structure can be declared within the structure.

Struct date {

Int day, month, year;

};

Struct history

{

Char name [25];

Struct date;

};

Structure can also be declared as array of structures.

3 comments:

Anonymous said...

thanks for the structure program problem.yes i have some confusion about that but its ok.

Anonymous said...

I am a new person in learning of C program.I think This post will help me.

Anonymous said...

I love to read and one of my friend give me your link to visit and i found your blog very interesting. I am trying to learn C by myself but is seems difficult. BTW thanks for your this helpful post :)