A.Aronia A.Aronia - 4 months ago 45
C Question

scanf generates a random number?

Hi I just started C as my first programming language.

I was playing around a bit with

and found something strange.

#include <stdio.h>
#include <Windows.h>
int main()
int x;

printf( " Type any number : " );
scanf( "%d", &x );
printf( "You entered %d.\n", &x );

return 0;

It always shows me a result of 7 or 8 digit number.

How is it possible?


You printf x's address instead of value. Fix like this:

printf("You entered %d.\n", x);

scanf wants the address where to store the result, printf can take the value itself.