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

Can the size of an array be declared at runtime?

0 Answers  


void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }

3 Answers  


What are the disadvantages of c language?

0 Answers  


how to write a prog in c to convert decimal number into binary by using recursen function,

1 Answers  


What are identifiers in c?

0 Answers  






What’s the special use of UNIONS?

0 Answers   ADP,


What are derived data types in c?

0 Answers  


Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….

1 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


How can you find out how much memory is available?

0 Answers  


What is structure padding and packing in c?

0 Answers  


program to find the second largest word in a paragraph amongst all words that repeat more thn twice

4 Answers   CTS, iGate,


Categories