Why doesn't the code "a[i] = i++;" work?

Answers were Sorted based on User's Feedback



Why doesn't the code "a[i] = i++;" work?..

Answer / guest

The variable i is both referenced and modified in the same
expression.

Is This Answer Correct ?    11 Yes 4 No

Why doesn't the code "a[i] = i++;" work?..

Answer / abdur rab

The answer from wikipedia

Sequence point comes into play when the same variable is
modified more than once. An often-cited example is the
expression i=i++, which both assigns i to itself and
increments i; what is the final value of i? Language
definitions might specify one of the possible behaviors or
simply say the behavior is undefined. In C and C++,
evaluating such an expression yields undefined behavior.

Is This Answer Correct ?    6 Yes 2 No

Why doesn't the code "a[i] = i++;" work?..

Answer / kk

undefined behaviour

Is This Answer Correct ?    7 Yes 3 No

Why doesn't the code "a[i] = i++;" work?..

Answer / vignesh1988i

this line will work.... first the value of i will be in the array and then i will get incremented

Is This Answer Correct ?    11 Yes 18 No

Post New Answer

More C Interview Questions

When do you say that a digraph is acyclic A)if and only if its first search does not have back arcs B)a digraph is acyclic if and only if its first search does not have back vertices C)if and only if its first search does not have same dfnumber D)None of these

1 Answers   Accenture, IBM,


Explain continue keyword in c

0 Answers  


What is the difference between %d and %*d in C

3 Answers  


print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5

7 Answers   IBM,


explain about storage of union elements.

2 Answers   ABC, Bosch,






what are the uses of structure?

7 Answers   HCL,


what is the difference b/w NULL and null?

3 Answers   HSBC, IBM,


what defference between c and c++ ?

6 Answers  


write a prgram of swapping with 2 valiables

6 Answers  


What is void pointers in c?

0 Answers  


What is adt in c programming?

0 Answers  


Can we compile a program without main() function?

0 Answers  


Categories