1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

why this code shows diffferent results

Discussion in 'C' started by arun12138, Dec 6, 2008.

  1. arun12138

    arun12138 New Member

    Joined:
    Dec 6, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    main( )
    {
    float a = 15.5 ;
    char ch = 'C' ;
    printf ( "\n%f %c", a, ch ) ;
    printit ( a, ch ) ;
    getch();
     }
    printit ( float sa, char sch )
    {
     printf ( "\n%f %c", sa, sch ) ;
    }
    this shows 15.5 C in main printf() and 0.00 in printit() why?
     
    Last edited by a moderator: Dec 6, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What compiler are you using?
    Does it work correctly if you redefine printit to void instead of default-int and place it above main (or prototype it)?

    Tried it in Visual Studio 2005 and it wouldn't compile because of the above; I set the return of printit to void and moved it above main and it worked fine.

    So I'd guess this is either a compiler bug or a consequence of some of the default behaviour you're relying on here (mainly that when the compiler finds printit in use it assumes its prototype is "int printit()" ).
     

Share This Page