I'm making a program that asks for a number, and then tells you what number you entered.
But when I enter a number, it just says 2293620 which is not the number I entered.
Here is the source code:
#include <stdio.h>
int main(void)
{
int i = 0;
printf("Please enter a number.\n");
scanf("%d", &i);
printf("You entered %d", &i);
return 0;
}
When you pass &i to scanf, you're saying "put it at the MEMORY ADDRESS of i". That's what & does; it gets the memory address of the specified variable. If you tried to pass "i", you'd tell scanf to overwrite memory address 0 with the number.
Printf, on the other hand, expects the value, not the memory address. Remove the &.
Thanks.
It works now.
Now the mods can lock the thread! :biggrin.gif:
But when I enter a number, it just says 2293620 which is not the number I entered.
Here is the source code:
What is wrong with the code? ;_;
If I deserve one, give me one.
Thanks.
It works now.
Now the mods can lock the thread! :biggrin.gif:
If I deserve one, give me one.