Why use symbol & when using scanf in C?

  • Thread starter jd12345
  • Start date
  • #1
256
2

Main Question or Discussion Point

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,614
501


"&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 for: Why use symbol & when using scanf in C?

  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
7
Views
644
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
9
Views
19K
Replies
3
Views
7K
Replies
9
Views
21K
Replies
4
Views
4K
Replies
13
Views
18K
Top