Monday 15 June 2015

Why in C input requires memory location of variable instead of name of variable itself? -


Is there any special reason that when selecting input the choice of memory of the variable instead of the name of the scanf variable Is it yourself? I have definition of scanf which is the mandate above? But is there any special reason? Like C ++, if you want to take input, you can use cin & gt; & Gt; Will write var; but why not? Is there anything to keep this language fast?

This is because values ​​working in C are passed by value < / Em>. And of course, the nominal languages ​​of the variable are not present at the time of being named, at that time there are all addresses in memory.

If you pass the variable directly, then you simply pass the value, which is required for printf () :

  int A = 32; Printf ("a =% d \ n", a);   

But if you have done this with the scanf () ', then it will get the integer value 32 , it did not know where it came from Was there. From the point of the caller variable to change scans (), you pass the address of the variable:

  int a = 32; Scanf ("% d", & amp; one);   

Then the code inside scanf () can enter a new integer value at the given address, causing a .

No comments:

Post a Comment