finding output of C code

Discussion in 'C' started by coder12, Nov 8, 2012.

  1. coder12

    coder12 New Member

    Joined:
    Sep 15, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    #include<stdio.h>
    #include<conio.h>

    double i;
    void main()
    {
    (int )(float)(char) i;
    printf("%d",sizeof(int )(float)(char) i));
    getch();
    }

    Give required explanation[/B]:crazy:
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    The only valid explanation of this code is that its author is an idiot.
     
  3. state

    state New Member

    Joined:
    Sep 14, 2011
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Hello there coder12
    If these are the exact LOC then you will get an error.
    "syntax error before '(' token "
    Assuming you mistyped,this is a question related to type casting.So what happens is i is casted to char then float and finally to int.As a result you get the o/p -->4(mingw).I don't think the output will vary much if you are using GCC.The gist of the matter is :sizeof(int).Type casts have R to L associativity
    Hope this helps
     

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