Explain output

Discussion in 'C' started by phiber_optik, Feb 18, 2008.

  1. phiber_optik

    phiber_optik New Member

    Joined:
    Feb 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I used Turbo C compiler
    Code:
    #include<stdio.h>
    #include<conio.h>
    #define STYLE1 char
    void main()
    {
     typedef char STYLE2;
     STYLE1 x;
     STYLE2 y;
     clrscr();
     x=255;
     y=255;
     printf("%d %d",x,y);
    }
    
    output: -1 -1
    Pls explain how?
     
  2. technosavvy

    technosavvy New Member

    Joined:
    Jan 2, 2008
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice