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 memcpy() function?
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
What is the use of linkage in c language?
can any one tel me wt is the question pattern for NIC exam
Explain what is wrong in this statement?
What is quick sort in c?
What are types of preprocessor in c?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
Write a program to swap two numbers without using the third variable?
What is the difference between NULL and NUL?
Is malloc memset faster than calloc?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
How can you access memory located at a certain address?
Explain pointers in c programming?
How can I prevent another program from modifying part of a file that I am modifying?