Pointer with index -1

Is negative indexing possible on a pointer?

hello @negative indexing is not even there in arrays .

https://ide.codingblocks.com/s/379265 But when I did this it worked ( b[-1] )?

@diganta_7777 this is because you are doing b++.
please see without doing it .

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 .

https://ide.codingblocks.com/s/379265 when I tried it’s working…

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!

hey @diganta_7777 if you feel that your doubt is cleared please mark this doubt as resolved .

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.