The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Heelpp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Discuss Heelpp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! in the C Programming forum on Dev Shed. Heelpp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 12th, 2013, 09:48 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 21 m 25 sec
Reputation Power: 0
|
|
|
Heelpp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
i'm a beginner so need some help ..
I made a program for addition of two intergers ...
but instead of the real value like 2+2=4
i get 2+2=2268633 something ...
i made a few more basic ones and im facing the same problem ,,,
is something wrong with my compiler ? or is it my mistake
btw im writing the code here
#include <stdio.h>
#include <conio.h>
int main(void)
{
int a;
int b;
int c;
printf("Enter two numbers:");
scanf("%d", &a);
scanf("%d", &b);
c = a + b;
printf("The addition is %d" , &c);
getch();
}
like for 2+2 i get 2293564
instead of 4
please help people !
|

January 12th, 2013, 10:03 AM
|
 |
Contributed User
|
|
|
|
> printf("The addition is %d" , &c);
Try just
Code:
printf("The addition is %d" , c);
Also, please use [code][/code] tags when posting code (see the sticky threads), and please drop the habit of excessive punctuation. It won't make anyone answer any quicker (the opposite is more likely).
|

January 12th, 2013, 02:42 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
&c is the address of the variable c, whereas c would be the variable and hence the value it contains.
In the call to printf, you want to print the value of c, not its address. Besides, if you did want to print the address, then you should have used "%p".
When you use scanf to input values into a and b, you do still need to use &a and &b, the addresses of a and b, because scanf needs to know where to put the value. scanf needs the address, printf needs the value.
|

January 12th, 2013, 08:49 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 21 m 25 sec
Reputation Power: 0
|
|
|
@dwise1_aol and @salem ..
Thank you guys ,,, It worked !
haha ! now i guess i can continue making more programs ... this error was holding me back
Have a nice day people
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|