Why use symbol & when using scanf in C?

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

When using scanf like in scanf("%d",&x); why do we use '&' before x? can't 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,797
583


"&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".
 

Suggested for: Why use symbol & when using scanf in C?

Replies
2
Views
224
  • Last Post
Replies
7
Views
1K
  • Last Post
Replies
1
Views
260
  • Last Post
Replies
2
Views
587
  • Last Post
Replies
11
Views
583
  • Last Post
2
Replies
36
Views
1K
Replies
2
Views
677
  • Last Post
Replies
1
Views
133
Replies
21
Views
102
Top