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

Explain continue keyword in c

767


What does c value mean?

856


to find the closest pair

2054


How can I find the modification date and time of a file?

812


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

805


What is Dynamic memory allocation in C? Name the dynamic allocation functions.

927


What the advantages of using Unions?

911


The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?

898


in iso what are the common technological language?

1851


Explain what are multibyte characters?

865


How do we print only part of a string in c?

801


how is the examination pattern?

1784


What are the header files used in c language?

781


What does the && operator do in a program code?

939


Explain the properties of union. What is the size of a union variable

920