Why does this work *add = add +1; but not this add++

Im using Dev c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>

void imfunction(int *add)
{
	*add++;
}

int main(int argc, char *argv[]) {
	int hello = 0;
	printf("\nhello = %d", hello);
	imfunction(&hello);
	printf("\nhello = %d", hello);

	
	return 0;
}

result is 
hello = 0
hello = 0

but when i change it to
*add = *add +1;

hello = 0
hello = 1
* has a lower priority than ++

*add++
is the same as
*(add++)

So your 'imfunction' is effectively doing nothing, as it is incrementing the pointer, dereferencing it, and then throwing the value away.

You would want this:
(*add)++
Topic archived. No new replies allowed.