EmbLogic's Blog

doubts of structure

struct abc{

char ch;

};

printf(“%d”,sizeof(abc));//prints 1 byte but

struct abc

{

int i;

struct a{

char ch;

};

}abc;

printf(“%d”,sizeof(abc));//prints only 4 bytes

but if we define the variable for struct a then it

prints the size along with the size of ch.

We want to ask if the structure is single then evem

if variable is not defined it shows the sizeof struct

but in nested structure it doesnt show sizeof that

struct whose variable is not defined.why??

2 Responses to doubts of structure

  1. struct a will not come into existence until its variable gets declared even when it is within another struct..

    it is as good as writing “int ;”
    (this will surely give a warning)

  2. Manoj says:

    there is no significance untill you declare a variable for the inner structure. thats why it gives warning that “declaration does not declare anything”.

Leave a Reply to saurabh.aggarwal Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>