c++ - Why this output? -


i have been trying understand of following c-program:

#include <stdio.h>  int arr[] = {1,2,3,4}; int count;  int incr(){  return ++count; }  int main(){      arr[count++]=incr();    printf("%d %d",count,arr[count]);        return 0; } 

the program gives 1 2 output,what not gtting why value of count 1 here , not 2 (since there 2 increments)?

the order of evaluation of operands of = operator unspecified in arr[count++]=incr(); , since both operands trying modify same global variable count result different on different compilers depending upon order of evaluation.

edit

actually behavior undefined (which means can happen) because "the prior value of variable count not accessed (only) determine value stored."


Comments