Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Explain output (http://www.go4expert.com/forums/explain-output-t8901/)

phiber_optik 18Feb2008 21:43

Explain output
I used Turbo C compiler

#define STYLE1 char
void main()
 typedef char STYLE2;
 STYLE1 x;
 STYLE2 y;
 printf("%d %d",x,y);

output: -1 -1
Pls explain how?

technosavvy 19Feb2008 11:09

Re: Explain output
because char is treated as signed char...
the range for signed char is -128 to 127 ...

now think on these terms
1) number is stored as its binary equivalent...
2) when a number is signed it most significant bit is always high i.e. 1
3) a negative number is represented as it's 2's compliment

i believe when u think on these terms..u will easily understand the o/p.

All times are GMT +5.5. The time now is 13:26.