1st problem format specifier is %d whereas memory is allocated only for short int memory allocated-2bytes. but being stored in 4bytes. so a is overwritten by b. In dis case where u give a=1, b=1, a becomes become 0. n so it gives:0+1=1 in d scanf if u use %hd instead u ll get d right output!!
On Thu, Jul 14, 2011 at 8:01 AM, nicks <crazy.logic.k...@gmail.com> 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 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. > -- 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.