0
Pointers
In the code inserted below : What is the meaning of ptr+i and why don’t we use ptr(i) ? int a[5] = {22, 33, 44, 55, 66}; int *ptr = NULL; int i; ptr = a; for (i = 0; i < 5; i++) { printf("%d ", *(ptr + i));
3 Respostas
+ 2
https://www.learncpp.com/cpp-tutorial/6-8a-pointer-arithmetic-and-array-indexing/#:~:text=The%20C%2B%2B%20language%20allows%20you,the%20previous%20integer%20before%20ptr%20.
This is called as pointers arithmetic, check this link, there is everything what you neeed
+ 1
>> why don’t we use ptr(i) ?
ptr(i) is an error, because ptr is not a function taking some argument; but ptr[i] is effectively equivalent to *(ptr+i) and can be used in place of that.
+ 1
Bilbo thanks