Weird Output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SlashGeek
    New Member
    • Dec 2011
    • 4

    Weird Output

    For the code given under, I'm getting 4200496 as output.

    #include<stdio. h>
    int main()
    {
    printf("%d",pri ntf);
    return 0;
    }
    Why I'm getting output for this code and what does the value signify???
    I've used DEV C++ IDE.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's probably printing out the address of the printf function but that's a guess on my part.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Yes, you are seeing the address of the printf function seen as an integer. To see it correctly as an address, use %p instead of %d.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        The %p format specifier is used for data pointers. The C Standard specifically allows for compilers implementations to implement function pointers differently than data pointers. Thus, portable code shouldn't use function pointers in a context (like %p) where a data pointer is expected. I can't think of a portable way to print the value of a function pointer; perhaps %lX.

        That said, I haven't yet encountered a compiler implementation where you couldn't get away with treating function and data pointers as if they were interchangeable .

        Comment

        Working...