-----Original Message-----
From: harry potter [mailto:[EMAIL PROTECTED]
Sent: Friday, December 24, 2004 7:40 PM
To: [EMAIL PROTECTED]
Subject: RE: (PT)output for this program
HI
THEN HOW DID WE GET THIS ANS 4.
FROM
KAPIL
--- Shyan Lam <[EMAIL PROTECTED]> wrote:
> Reply embedded...
>
> > From: Shankar Murugan
> [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, December 22, 2004 2:53 AM
> > To: [EMAIL PROTECTED]
> > Subject: (PT)output for this program
> >
> > #include<stdio.h>
> > #include<conio.h>
> > struct man
> > {
> > int a:5;
> >
> > };
> > man india;
> >
> > void main()
> > {
> >
> > int z;
> > z=sizeof(man);
> > printf("%d",z);
> > }
> >
> > the output for this is 4 (VC++), lemme know how
> this happens,when bitwise
> > operator is given as 5 .
>
> In VC++, sizeof(int) is 4. So 'a' has 32-bits
> (CHAR_BIT is 8) but you only
> use 5. As a result, 27 bits are wasted.
>
> You cannot take the size of a bit-field.
>
> HTH
> Shyan
>
>
>
>
Hi
VC++ is a 32bit compiler. In 32bit mode a int type is 4 bytes. In 32bit
mode, the compilers add something called padding for faster access by the
processor. For example, we all know that char is 1 byte but when we use it
inside a struct that has other variables, the compiler adds padding in order
to make struct to a size multiple of 4 bytes. So I guess that explains why
the output of vc++ is 4 bytes.
Regards
Surej
------------------------ 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=4808
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/