Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Why use symbol & when using scanf in C?

  1. Sep 8, 2012 #1
    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
     
  2. jcsd
  3. Sep 8, 2012 #2

    rcgldr

    User Avatar
    Homework Helper

    Re: Why use symbol "&" when using scanf in C?

    "&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".
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Why use symbol & when using scanf in C?
Loading...