scanf takes a pointer argument.. Why cant we pass a pointer variable?
int* x;
scanf("%d", x);
printf("%d", *x);
This does not give output.. Why? What is wrong?
scanf takes a pointer argument.. Why cant we pass a pointer variable?
int* x;
scanf("%d", x);
printf("%d", *x);
This does not give output.. Why? What is wrong?
The %d format specifier to scanf expects a pointer to an int, i.e. a int *, which is what you are passing. So you're calling the function correctly.
Where you went wrong is that the pointer x was never initialized and therefore doesn't point anywhere. scanf then attempts to read this unitialized value as an address and subsequently read what is at that bogus address. Reading an uninitialized value invokes undefined behavior.
You need to make x point somewhere, either by assigning it the address of an int variable or by using malloc to dynamically allocate memory.
int a;
int *x = &a;
Or:
int *x = malloc(sizeof(int));