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,721
543


"&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
761
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
9
Views
19K
Replies
3
Views
7K
Replies
9
Views
22K
Replies
4
Views
5K
Replies
13
Views
18K
Replies
1
Views
7K
Replies
10
Views
4K
Top