# Thread: Some basic doubts in pointer arithmetic

1. ## Some basic doubts in pointer arithmetic

Hello,

I'm learning one embedded system course online, and while watching one of those video, I had some doubts about pointer arithmetic,

c - Increment char pointer - Stack Overflow

Code:
```#include <stdio.h>
void foo1(char **p) { *p++; }
void foo2(char **p) { *p += 1; }

int main()
{
char *s = "abcd";
char *a = s;
foo2(&a);
printf("%s", a); //abcd
}```

OUTPUT : abcd

Q1. Why the parameter of foo1() is double pointer?

I understand how the program works. character pointers are stored in memory like this

*p++ ==> *(p++)

p = &a = 500

Derefenceing p will give 100 (address of first character), then increment the pointer, now p is 501

But I don't understand this

Code:
```#include <stdio.h>
void foo1(char **p) { *p++; }
void foo2(char **p) { *p += 1; }

int main()
{
char *a = s;
foo2(&a);
printf("%s", a); //bcd
}```
how output becomes bcd??

Is it this way
p = 500 (address of a)

*p += 1
*p = *p+1 = *500 + 1 i.e., dereferencing pointer p will give 100(address of first character)
=> *p = 100 + 1
=?*p = 101 ==> p is 500, it's content now changed form 100 to 101,

Now content of a is 101
Is this how his program works?

Thanks Athul

2. Presumably your first example is supposed to call foo1 and your second is supposed to call foo2 (with a properly defined s).

The postfix increment operator has higher precedence than the dereferencing operator. So foo1 actually says the following and therefore does absolutely nothing. If you are compiling with full warnings you should get a warning.
Code:
`void foo1(char **p) { *(p++); }  // This is how *p++ is interpreted by the precedence rules`
To make foo1 actually do something (acting like foo2) :
Code:
`void foo1(char **p) { (*p)++; }`
Or more intelligently, IMO :
Code:
`void foo1(char **p) { ++*p; }`
Your explanation of why foo2 (and the new-and-improved foo1) do what they do is correct.