Incrementing array problem

What is the output of the following problem

int i = 1;
int arr[10] ;
arr[i] = i++;
printf (“%d",arr[i]) ;

Re: Incrementing array problem

[quote="geekgod"]What is the output of the following problem

int i = 1;
int arr[10] ;
arr[i] = i++;
printf (“%d",arr[i]) ;[/quote]

after assigning arr[i]=i++ i hasbeen incremented so now i=2
arr[1]=1
&
arr[2]=some garbage value this wil be the o/p

Incrementing array problem

It will print garbage since i becomes 2 in the previous statement. hence arr[2]=uninitialized(garbage) :?

Incrementing array problem

uNDEFINED BEHAVOIUR NOT THE GARBAGE VALUE :?:

Incrementing array problem

Why is it garbage??

Incrementing array problem

small doubt.. GARBAGE value is right..

eventhough it is compiler dependent , the output wud again be garbage rite!!

say me if i m wrong...

Incrementing array problem

it wuld be arr[ i] = 1.
after this execution, the value of i wuld be incremented to 2.

thanx
PRABH

Incrementing array problem

Well the real question is if it will do
arr[2]=1
or
arr[1]=1
or
arr[1]=2
etc...

This is another programming questions i have seen that gets asked in interview tests... and usually one of the choices above is given to the user to pick the right one..

The question is flawed thought, since the evaluation order is not a ANSI C standard and hence this is really compiler dependant.. You will get different results with different compilers

easy

Obviously, it would be a garbage value printed.

thanx

PRABH :D