+ 1

Why used ampersand(&) in C/C++ for scanf method...

I want to know about ampersand(&) that why used in scanf() method...

23rd Aug 2017, 3:00 PM
Muhammad Belal
Muhammad Belal - avatar
6 Respuestas
+ 2
@Sayan Chandra, a small adjustment, an int requires 4 bytes (32 bits). Cheers!
23rd Aug 2017, 4:39 PM
Ipang
+ 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)
23rd Aug 2017, 3:04 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
Because it's stored as pointers, you use the reference operator so you can store the result to your normal variable.
23rd Aug 2017, 3:06 PM
AgentSmith
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)
23rd Aug 2017, 3:11 PM
sayan chandra
sayan chandra - avatar
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....
23rd Aug 2017, 5:13 PM
sayan chandra
sayan chandra - avatar
- 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
23rd Aug 2017, 3:18 PM
sayan chandra
sayan chandra - avatar