C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-03-2008, 11:48 PM   #1
Registered User
 
Join Date: Dec 2008
Posts: 14
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
Demipimp is offline   Reply With Quote
Old 12-04-2008, 12:00 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,356
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("%d", f);

    getchar();

    return 0;
}
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Old 12-04-2008, 12:14 AM   #3
Registered User
 
Join Date: Nov 2008
Posts: 25
Wow, I actually sort of knew that. Astonishing.
newbcore is offline   Reply With Quote
Old 12-04-2008, 12:36 AM   #4
Registered User
 
Join Date: Dec 2008
Posts: 14
Thumbs up

God Ham ok right OMG I forgot
Demipimp is offline   Reply With Quote
Reply

Tags
error

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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