--- Kapil <[EMAIL PROTECTED]> wrote:

> 
> > 
> > 
> > Hi Sasi,
> > I have a turbo C compiler (16 bit)..
> > 
> > I have tried both the ways and I am getting the
> same
> > result both the ways... The result is 3 due to 16
> > bit...
> > 2 for int 
> > 1 for char
> > 
> > Please recheck it ...
> > 
> > Regards
> > Ashwin Mittal.
> 
> You are working on a pathetic 8 bit OS which assumes
> the processor to be 
> 8088 only. Hence the memory allocation is in
> multiples of 1 byte so in dos
> struct abc {
> int a;
> char b;
> };
> will yield a sizeof value 3 bytes
> 
> however on 32 bit OS es like Linux / windows
> nt/2000/xp you will get 
> value as 8 bytes only.
> 

hey you have modified my answer..................
The question which is being posted goes like this


> 
> >    From: Himanshu Arora <[EMAIL PROTECTED]>
> > Subject: What's wrong with this?
> > 
> > 
> > Look at the following three codes
> > 
> > struct abc{
> > int a;
> > }
> > 
> > int main()
> > {
> > abc X;
> > cout<<sizeof(X);
> > }
> > It gives me output of  4 as expected.
> > 
> > Now,
> > 
> > struct abc{
> > char a;
> > }
> > int main()
> > {
> > abc X;
> > cout<<sizeof(X);
> > }
> > 
> > This gives me 1 as output.
> > Now if i try 
> > 
> > struct abc{
> > int a;
> > char b;
> > }
> > int main()
> > {
> > abc X;
> > cout<<sizeof(X);
> > }
> > why is it giving me output as 8 ??
> > I m confused .I've tried both gcc and borland
> > compiler,the output is same.
> > Pls clear my concepts.
> > Thnx
> > Himanshu
> > 
> Himanshu,
> 
> This is the padding concept. Whenever the structure
> is
> instantiated in the memory, the memory allocation
> takes place based upon its elements' arrangement. If
> the default size of the element place first in the
> memory is larger and the default size of second(and
> so
> forth) elements are smaller then the system reserves
> the memory in the multiples of the first elements
> size(which is larger in size) 
> In your example if you'll rerrange the code like
> following then you'll get the correct result:-
>  struct abc{
>  char b;
>  int a;
>  }
> 
> regards,
> :-)Sash:-)
> 
> 

>Hi Sasi,
>I have a turbo C compiler (16 bit)..

>I have tried both the ways and I am getting the same
>result both the ways... The result is 3 due to 16
>bit...
>2 for int 
>1 for char

>Please recheck it ...

>Regards
>Ashwin Mittal.



and even if you rearrange the code

like this
struct abc
{
char a,
int b
}

instead of

struct abc
{
int a,
char b
}

then in both the cases result is same......

even on gcc compiler ...the answer is 8.......

Okay Kapil..  I think you have got my point....

Ashwin Mittal.





                
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4556
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to