For Problem 1, scanf tries to read 8 bytes from console (2 interger
due to %d) and it starts writing in memory from right to left. since
the variable are defined as short only two bytes will be stored.

bytes read by scanf
0 0 0 1 0 0 0 1
from right to left first 2 bytes that will be stored to b is 0 and 1
next two bytes that will be stored to a is 0 and 0

Hence b is 1 and a is 0
which makes c as 1

try with
1 16777215
you will find value of a is 255 , b is -1 and c is 254

On Thu, Jul 14, 2011 at 8:27 AM, John Hayes <[email protected]> wrote:
> Hey Guys, plz help me in getting these 2 C output problems
>
> 1st problem
>
> #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 No. 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.
>



-- 
Sanjay Ahuja,
Analyst, Financing Prime Brokerage
Nomura Securities 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.

Reply via email to