int k = 0; int g() { k = k + 1; return k; }
int D[] = {13, 19, 47, 3, 7};
…..
D[ g() ] = D[ g() ]++  —  D[ g() ]++;

According to a book from which this problem comes this code will generate 5 to 6 different results according to different implementations of the C standard semantics...

I have found 2 results based on Visual studio and GCC C compilers: Those are
D={13,20,48,-28,7} Visual studio
D={13,44,48,4,7} GCC

This is obviously due to the order of execution of the assignment operator.

I am not able to determine what 4 other set of values can be obtained using the standard C semantics.

The book gives a hint that it has to do with the assignment operator and one rule in Standard C semantics... it's not related to associativity ..................... This makes it even more confusing

>This is obviously due to the order of execution of the assignment operator.
That's Undefined Behavior .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.