+ 1
Why we are using "&" when we denote a string in c and c++..???? Example :scanf("%d",&a)
4 Respostas
+ 2
Why we are using "&" when we denote a string in c and c++..???? Example :scanf("%d",&a)
Answer:We use &a to pass the reference to the variable a. If we would just pass a, scanf would get, say, '5' (if that's the value a had) and no way of modifying the variable. Instead we pass a reference to the physical location of a, so scanf can go there and change it for us.
+ 2
The & sign is simply stating that whatever value is inputted should head to the address of the string, int, etc. This address is a hexadecimal that the computer will point to whenever the data value is called. The & is simply assuring that the input goes to the address of the data.
+ 2
& simply refers to the memory address of the variable we declare. Eg in this, & is referring to the memory address of a amd telling the function scanf() to get the input as integer (%d) amd store it at the memory address which is denoted by a. .
Hope this clears you doubt :)
+ 1
We use &a to pass the reference to the variable a. If we would just pass a, scanf would get, say, '5' (if that's the value a had) and no way of modifying the variable. Instead we pass a reference to the physical location of a, so scanf can go there and change it for us.