Why use symbol & when using scanf in C?

  • Thread starter jd12345
  • Start date
  • #1
256
2
Why use symbol "&" when using scanf in C?

When using scanf like in scanf("%d",&x); why do we use '&' before x? cant we write directly ,x as in printf command? Is it just a convention? I think it should have a reason.. they won't just put an "&" just like that
 

Answers and Replies

  • #2
rcgldr
Homework Helper
8,775
572


"&x" means to generate a pointer to "x". Scanf needs a pointer to x in order to store the value and change "x". Printf uses a copy of the value of "x" passed as a parameter (usually on the stack), since it isn't changing the value of "x".
 

Related Threads on Why use symbol & when using scanf in C?

  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
7
Views
890
  • Last Post
Replies
4
Views
2K
Replies
2
Views
2K
Replies
5
Views
4K
Replies
6
Views
2K
Replies
15
Views
19K
Replies
3
Views
7K
  • Last Post
Replies
9
Views
20K
Replies
9
Views
22K
Top