C: Operator precedence Issue
Thursday, 03 June 2010 07:25

I just came a across a fun/classic C operator precedence issue. I've never been a fan of the '++' and '--' operators for this exact reason. Below is an example you can play with yourself.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int x = 5;
	int * y = &x;

	(*y)++;
	printf("x = %d\n",*y);

	*y++;
	printf("x = %d\n",*y);

	return EXIT_SUCCESS;
}