hmm... for question number 1.. .. u can understand more easliy with the
following examlple
#include<stdio.h>
// 1. #include<stdio.h>
#pragma pack(1)
struct value
{
int a;
int bit3: 4;
int bit4: 4;
};
#pragma pack()
int main()
{
struct value bit;
printf("%d",sizeof(bit));
system("pause");
return 0;
}
here size is 40 bits.(take int of 4 bytes).. so 5 bytes... if you don't use
pragma directives... compiler assignes location as multiple of 4 for fast
processing.. google it you'll find
for question number 2:
all your structure elements are signed so bit 1 cannot take any int value as
it has got only 1 bit.. so if you declare bit1 as unsigned
you will get fine output.. in bit3 and bit4 ..you will get fine answer if
value from(0 to 7)
i hope you got it
for question number 3;
ya you can use bit fields in union..
On Sun, Jun 13, 2010 at 2:59 PM, divya <[email protected]> wrote:
> tell the o/p of following with explanations
>
> 1. #include<stdio.h>
> int main()
> {
> struct value
> {
> int bit1:1;
> int bit3:4;
> int bit4:4;
> }bit;
>
> printf("%d\n",sizeof(bit));
> return 0;
> }
>
> 2.
> #include<stdio.h>
> int main()
> {
> struct value
> {
> int bit1: 1;
> int bit3: 4;
> int bit4: 4;
> } bit={1,2,2};
> printf("%d %d %d\n",bit.bit1,bit.bit3,bit.bit4);
> return 0;
> }
>
> 3 can bit field be used in union??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.