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
When c language was developed?
How do you search data in a data file using random access method?
Explain what is wrong in this statement?
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
What is a macro in c preprocessor?
Why is c used in embedded systems?
In a switch statement, explain what will happen if a break statement is omitted?
Explain how can you tell whether two strings are the same?
Can i use “int” data type to store the value 32768? Why?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
How to get string length of given string in c?
How do you initialize pointer variables?
What is the function of multilevel pointer in c?
Distinguish between actual and formal arguments.
When should a type cast not be used?