+ 1
Why used ampersand(&) in C/C++ for scanf method...
I want to know about ampersand(&) that why used in scanf() method...
6 Réponses
+ 2
@Sayan Chandra, a small adjustment, an int requires 4 bytes (32 bits).
Cheers!
+ 1
Because scanf takes a pointer as parameter, not a simple variable (you'll need to comprehend the pointer part of the course to understand it)
+ 1
Because it's stored as pointers, you use the reference operator so you can store the result to your normal variable.
0
int a;
scanf("%d",&a);
now a is a space in your device memory
a stores whatever integer you scan from keypad / key board
as a is the memory allocated by you assiging int a(2 bytes for int)
when scanning the integer the system can't find the memory by its name that is 'a'
so u need to give its address...
address of a is &a
### as a pointer variable stores a variable's/a pointer's adress so we also say that scanf takes a pointer type as its
parameter...
### for better understanding see it as an address (which is basic)
0
ya...
i just gave him priliminary concept...
and yes
for 16 bit processor int 2 bytes
for 32/64 bit processor int 4 bytes..
👍✌lpang....
- 1
### also try printing the address by printf("%u",&a)
% u is for integer-adress type
remember address is always a positive integer....not 0 and not 1