output is -4 -1
int a:1 signifies that only 1 bit will be stored for a and since we have
only 1 bit so it will serve as sign bit and we get obj.a as -1
similarly for int b:3, 3 bits will be used to store b. 12 is 1100. we save
only 3 bits i.e. 100 where msb signifies the sign i.e. no. is negative. But
I am not able to represent the value -4 in 3 bits. Can anyone elaborate?
I think 00 is getting converted to 2's complement which is 100 = 4 and we
have negative sign bit set. So ans is -4. Correct me if I am wrong.

On Wed, Sep 21, 2011 at 10:22 PM, kartik sachan <kartik.sac...@gmail.com>wrote:

>
> int main(){
>         struct {
>                 int a:1;
>                 int b:3;
>                 }obj;
>         obj.b=12;
>         obj.a=7;
>         printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("%d 
> %d",obj.b,obj.a);return 0;}
>
>
>
> can anybody explain the output
> plzz also show how no's are stored
>
>
> --
>
> *WITH REGARDS,*
> *
> *
> *KARTIK SACHAN*
>
> *B.TECH 3rd YEAR*
> *COMPUTER SCIENCE AND ENGINEERING*
> *NIT ALLAHABAD*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards
Ravi Maggon
B.E. CSE, Final Year
Thapar University

www.algorithmguru.com

"*Failure is the opportunity to begin again more intelligently"*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to