Every time I use %d I get an incorrect number

This is a discussion on Every time I use %d I get an incorrect number within the C Programming forums, part of the General Programming Boards category; I am using Dev C++ and the code looks like this Code: #include <stdio.h> int main( void ) { int ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    20

    Every time I use %d I get an incorrect number

    I am using Dev C++ and the code looks like this



    Code:
    #include <stdio.h>
    
    
    int main( void )
    
    {
    
    int f = 2;
    
    printf("%d", &f);
    
    
    
    
    
    getchar();
    
    
    
    return 0;
    }
    it gives me


    2293620

    halp plz

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Since you want to print the value of f, you should not be taking its address:
    Code:
    #include <stdio.h>
    
    int main( void )
    {
        int f = 2;
    
        printf("&#37;d", f);
    
        getchar();
    
        return 0;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    25
    Wow, I actually sort of knew that. Astonishing.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    20

    Thumbs up

    God Ham ok right OMG I forgot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  2. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 01:43 PM
  3. How can I read one number at a time?
    By Bad_Scooter in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2003, 09:58 PM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 04:00 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21