If n has 3, then the statement a[++n]=n++;
for the variable "n".There are two things:
1) Use "n" as the index of the array a.(After doing ++n)
2) Increment the the value of "n" by 1.(by doing n++)
Now, the confusion is :
whether to use the value of "n" before it is modified (incremented by doing n++) as the index, or after it . Different compilers will try to solve this confusion, by doing something like:
a) doing ++n on the value of "n" first (to be used as the index)
b) doing n++ first, and then ++n to calculate the index
This is undefined behaviour, and will depend on how a particular compiler handles such situation.
for more examples on undefined behaviour,
refer: https://en.wikipedia.org/wiki/Undefined_behavior [see the example section].
if undefined wasnt given in the option then ? which u think would hv been the answer?
@shweta1920 if undefined wasnt given in the option then option 3 would be the ans.