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


Please Help Members By Posting Answers For Below Questions

What is meant by realloc()?

676


How can I convert a number to a string?

606


what are # pragma staments?

1625


How do c compilers work?

609


can anyone please tell about the nested interrupts?

1674






What are the disadvantages of external storage class?

588


Explain what is the difference between the expression '++a' and 'a++'?

626


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.

2269


Are enumerations really portable?

594


Is c pass by value or reference?

595


What is context in c?

541


What are the advantages of using new operator as compared to the function malloc ()?

756


Why is structure important for a child?

601


What is the correct code to have following output in c using nested for loop?

611


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

1626