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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -