value of b = 10 (in binary) and since b is a signed integer and also MSB is 1 so final value of b is 2's complement of 10 i.e. -2
On Sun, Jul 17, 2011 at 12:55 AM, Kamakshii Aggarwal <[email protected]>wrote: > @gaurav :y it is -2?y not +2? > > On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh <[email protected]>wrote: > >> for problem1 you can use %hi or %hd .. while scanning .. >> >> >> On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain <[email protected]>wrote: >> >>> @Nicks >>> *Problem 1* >>> >>> %d is used to take a signed integer as input. To take a short integer as >>> input, use %hi. That way, you would get the correct answer as 2. >>> >>> *Problem 2:* >>> a:1 means that variable a is of width *1 bit* >>> Similarly, b:2 means that b is of width *2 bits* >>> >>> b = 6 sets the two bits as 10, (last two bits of 110 considered), which >>> is equal to -2 >>> a = 2 sets the only bit as 0, (last bit of 10 considered), which is >>> nothing but zero. >>> >>> Bit-fields like these however tend to be implementation-dependent and in >>> the interest of portability should be avoided. >>> >>> t.b = 6 sets the last two bits of b as 10, which is -2 in 2's complement >>> t.a = 2 sets the >>> On Thu, Jul 14, 2011 at 1:18 AM, nicks <[email protected]>wrote: >>> >>>> Hey Guys, plz help me in getting these 2 C output problems >>>> >>>> *PROBLEM 1>.* >>>> * >>>> * >>>> *#*include<stdio.h> >>>> int main() >>>> { >>>> short int a,b,c; >>>> scanf("%d%d",&a,&b); >>>> c=a+b; >>>> printf("%d",c); >>>> return 0; >>>> } >>>> INPUT- >>>> 1 1 >>>> >>>> OUTPUT >>>> 1 >>>> >>>> i am not getting why 1 is coming in the output.....what difference is >>>> using short making in the code ??? >>>> >>>> >>>> *PROBLEM 2>.* >>>> * >>>> * >>>> * >>>> * >>>> #include<stdio.h> >>>> main() >>>> { >>>> struct >>>> { >>>> int a:1; >>>> int b:2; >>>> }t; >>>> t.b=6; >>>> t.a=2; >>>> printf("%d %d",t.a,t.b); >>>> } >>>> >>>> OUTPUT >>>> 0 -2 >>>> >>>> What does the statement a:1 and b:1 mean and what are they doing.....i >>>> am seeing them first time ever...hence not able to get the output....if >>>> someone has any idea plz help !! >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Gaurav Jain >>> Associate Software Engineer >>> VxVM Escalations >>> Symantec Software India Pvt. Ltd. >>> >>> >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > > > -- > Regards, > Kamakshi > [email protected] > > -- > 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. > -- 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.
