+ 2

scanf("%d",&a[i]);

Pls explain this syntax

20th Nov 2016, 6:05 AM
B Shardiya
4 Answers
+ 5
@scott johnson is correct ampersand (&) is used to reference the address to which you wish to enter the integer. just a little addition when using arrays to input some data, there is no need for & before, as an array is an address, and an array at index (arr[2] for example) is simply the the address: starting address + 2*sizeof array datatype for a single variable however (int x; or something similar), you do need to have & before it when wanting to enter data into it using scanf.
20th Nov 2016, 6:51 AM
Burey
Burey - avatar
+ 4
%d is for an integer and a[i] is probably an array. So you're reading in input from the keyboard that is expected to be an integer that will be put into the array at index i. As for the ampersand, I'm not entirely sure in this context as I'm more familiar with C++ than C. A single ampersand is usually used for a reference or address. Edit: Just did a bit of research. What you're saying is: Read this data into this address location.
20th Nov 2016, 6:11 AM
scott johnson
scott johnson - avatar
+ 2
😂😀 no
30th Dec 2016, 12:03 PM
B Shardiya
0
OK
30th Dec 2016, 12:41 PM
ADITYA DHADKE
ADITYA DHADKE - avatar