main()
{
int i = 1;
int num[] = {1,2,3,4};
num[i] = i++;
printf("%d", num[i]);
}
what will be the output?
}
Answer Posted / james holdcroft
The output will be 1 or 3, depending on the compiler.
Quoting from "The C Programming Language, Second Edition"
by Kernighan and Ritchie:
C, like most languages, does not specify the order in which
operands of an operator are evaluated. (The exceptions are
&&, ||, ?:, and ','.)
...
One unhappy situation is typified by the statement
a[i] = i++;
The question is whether the subscript is the old value of i
or the new. Compilers can interpret this in different
ways, and generate different answers depending on their
interpretation.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what is a constant pointer in C
What is the purpose of 'register' keyword in c language?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
Differentiate between functions getch() and getche().
how logic is used
What does printf does?
Explain function?
Can we compile a program without main() function?
How can this be legal c?
When should you not use a type cast?
What is a constant and types of constants in c?
What is the use of c language in real life?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
How can I implement sets or arrays of bits?
Define circular linked list.