Assuming int
is 4 bytes on your computer, then replace sizeof(int)
with 4:
t = (p+= 4))[-1];
- just move the pointer p
4 of the element and move back 1 element, and then get the element.
In this example, the array has 4 elements, so move forward to one end and move back to the last element, which is "gh"
.
A few notes:
a[-1]
is just *(a - 1)
.- You need to make sure that when you do pointer arithmetic, they always point to an element in an array or one by one.
- Also, the name
argv
not a good idea, since we usually use it to refer to the main
parameter.
source share