in Programming in C edited by
1,822 views
2 votes
2 votes

#include <stdio.h>

int arr[] = { 10, 20, 30, 40, 50 };

static int count ;

inc() {

return ++count;

}

int main()

{

arr[count++]=inc();

printf("%d ", arr[count]);

printf("%d ", arr[0]);

}

https://ideone.com/5LOuqj 

 

in Programming in C edited by
1.8k views

4 Comments

when post-increment happens a temporary variable is created which stores the initial value but original variable is incremented at the moment.

that's why when inc() is executing it finds count with value 1.

0
0

https://ideone.com/5LOuqj 

yes it is 30 2

0
0

3 Answers

0 votes
0 votes

the answer is 30,2 here

 

4 Comments

here calculated address of 'a', which can't effect by first executing LHS or RHS part of '='
0
0
have u any reference? I havenot got how r u telling that for = it is giving undefined behaviour
0
0
It's not undefined expression , [ ] has higher precedence than = , it will evaluate first,including the expression inside the [].

Answer must be 30 2.
0
0
0 votes
0 votes
0 votes
0 votes
undefined behaviour  Sequence Point Problem.

arr[count++]=inc();

arr[count++]=++count;

1 comment

it's undefined behaviour due to which side of '=' evaluate first but not sequence problem !
0
0

Related questions