/********* * test.c * * testing foo->bar++ syntax ... * and also giving a tiny "object-oriented-like coding in C" example * * $ gcc test.c -o test * $ ./test * f->bar is 2 * **********/ #include #include typedef struct _foo *foo; // foo is a pointer to (struct _foo) struct _foo { // a (struct _foo) has a .bar property int bar; }; // allocate space for a (struct _foo) and return a pointer to it. foo new_foo(){ foo f = malloc(sizeof(struct _foo)); f->bar = 0; // equivalent code : (*f).bar=0 return f; } int main(){ foo f = new_foo(); // make one f->bar++; // increment f->bar to 1 (this syntax is OK) (f->bar)++; // increments again to 2 (this syntax is also OK) printf(" f->bar is %d \n", f->bar); // prints "is 2" return 0; }