Is negative indexing possible on a pointer?
Pointer with index -1
hello @negative indexing is not even there in arrays .
So if int*b =a[1]…this would work too? In short if there is something available before 0th index it will work?
no it wouldn’t work .
it would give you any garbage value .
Sorry I meant to say int *b=&a[1]…cout<<b[-1]…would this print a[0]?
i have just tried but the ouput coming is different .
hey @diganta_7777 just try to understand this :
when you have done like int *b=a;
then in this way b is allocated from the starting element of a i.e index 0 .
but when you have done b++ then it is starting from the second element of the a array i.e 1st index .
that why b[0] is first indexed element of the array and b[-1] is the oth indexed element of the array .
but b[-2] produces the garbage value .
OK! Understood! Thank You!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.