CPP - Pointers PDF

Addition of an address by a constant integer value i.e. ptr +5 means address of cell which is 5 * sizeof(*ptr) away from ptr.
Please explain this line.

Hey @yajurkhurana
Bassically assume
int*arr =new int[10];
Here assume pointer to an array
than
arr+1 is pointing to 1st element
arr+2 is pointing to 2nd element and so on

Simillarly now assume its not an array just an integer even then it will go that many bytes ahead

So intarr=&b;
Now if arr is pointing at X
then arr+1 points at X+4 //4 is size of int
arr+2 points at X+8 //2
4
and so on

I didn’t get this part of the answer you gave me.
Can you please explain it again?

Basically if
arr is pointer of Y type and pointing to X address

then arr+i will point to address X+sizeof(Y)*i

So
if its an integer pointer then sizeof(int)=4
if char then sizeof(char)=1
and so on

So rest is just simple mathematics

Check this : https://ide.codingblocks.com/s/378360

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.