Possible Duplicate:
Why doesn't scanf need an ampersand for strings and also works fine in printf (in C)?
In C when we use the scanf() function to get user input, we always use the & sign before the variable.
For example:
scanf("%d", &number);
scanf("%c", &letter);
This ensures our input is stored in proper address. But in case of a string we do not use &.
Why is that?
A “string” in C is the address of a character buffer.
You want
scanfto fill the memory in the buffer, which is pointed to by the variable.In contrast, an
intis a block of memory, not an address. In order forscanfto fill that memory, you need to pass its address.