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

What is the advantage of an array over individual variables?

0 Answers  


define function

4 Answers   Assurgent, Sonata,


What does static variable mean in c?

0 Answers  


what is the different between if-else and switch statment (other than syntax)

26 Answers   CTS, Oracle, Scorpos,


What do you mean by dynamic memory allocation in c?

0 Answers  






Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

0 Answers  


what is the diffrenet bettwen HTTP and internet protocol

0 Answers  


what is out put of the following code? #include class Base { Base() { cout<<"constructor base"; } ~Base() { cout<<"destructor base"; } } class Derived:public Base { Derived() { cout<<"constructor derived"; } ~Derived() { cout<<"destructor derived"; } } void main() { Base *var=new Derived(); delete var; }

3 Answers   Honeywell,


Differentiate between calloc and malloc.

0 Answers   Wipro,


why Language C is plateform dependent

3 Answers   Siemens, Wipro,


What is the difference between int main and void main in c?

0 Answers  


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

0 Answers   Huawei,


Categories