Associativity of assignment operator in C -


this question has answer here:

i have code:

#include<stdio.h> main() {     static int a[10];     int  i=5;     a[i]=i++;// **statement 1**      printf("%d %d",a[6],a[5]); } 

i following output:
0 5
since assignment operator rtl, shouldn't i++;in statement 1 incremented , a[i] becomes a[6] before assignment?
doesn't statement 1 evaluate a[6]=5;?
why a[5] becoming 5?

this becuase = not sequence point c language. such, a[i] = i++ invokes undefined behaviour.

this better explained here, , here (thanks daniel fischer)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -