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 meant by realloc()?
How can I convert a number to a string?
what are # pragma staments?
How do c compilers work?
can anyone please tell about the nested interrupts?
What are the disadvantages of external storage class?
Explain what is the difference between the expression '++a' and 'a++'?
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
Are enumerations really portable?
Is c pass by value or reference?
What is context in c?
What are the advantages of using new operator as compared to the function malloc ()?
Why is structure important for a child?
What is the correct code to have following output in c using nested for loop?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)