What is the meaning of this line ? (C++)

i read someone code and found something interesting

here the link

the line i asked is

scanf("%d", v + i);
what the meaning read one var for two?

In C and C++, the name an array represents the base address or the address of the first element of the array. i.e. if you do scanf("%d", v ); (where v is array name), you are scanning v[0]. Also to access further elements of the array, you can specify how much you want to travel from this base address. example: v+0 will be the first element. v+1 will be the second element i.e. v[1], etc. It depends on which notation you want to use but the standard is arr[i] where i is the (i+1)th element of the array.(assuming you start i from 0)

v[i] is equivalent to (v + i) in c and c++
This basically will let you input at i th element in an array

1 Like
//