main()
{
int i = 1;
int num[] = {1,2,3,4};
num[i] = i++;
printf("%d", num[i]);
}
what will be the output?
}
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / aniruddha
It will print answer 1 because in case of++ atfairt assing
and then increment..
| Is This Answer Correct ? | 5 Yes | 6 No |
Answer / ismail
2 is the ans
num[i]=i++
num[1]=2
now num[1] is changed with 2(same as the previous value)
now to print num[i]=num[1] right?
its 2 which is in num[1] solved!!!!
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / vijay
main()
{
int i = 1;
int num[] = {1,2,3,4};
num[i] = i++; //num[2]=1; after compile time
printf("%d", num[i]);
}
}
output:- 1
//if you have R&D mode then send the your view .No doubt ,
//it is correct.
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / abdur rab
it will lead to Undefined behaviour, both answers 3 aand 4
are correct.
| Is This Answer Correct ? | 0 Yes | 5 No |
Answer / raju
correct answer is 2 bcz once assign only that will take as
that value
| Is This Answer Correct ? | 0 Yes | 6 No |
how to find the size of the data type like int,float without using the sizeof operator?
What does volatile do?
What is a far pointer in c?
WAP to convert text into its ASCII Code and also write a function to decode the text given?
The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this
What are the types of assignment statements?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
2 Answers HCL, IBM, Satyam, Vimal, Vimukti Technologies,
What is a const pointer in c?
what is the output of below code int x=8,y; x>>=2; y=x; what is y value. NOTE:EXPLANATION IS COMPALSARY with binary bits
What is the difference b/w Structure & Class?
Write a program in c to print 1 121 12321 1234321 123454321
11 Answers ANR, College School Exams Tests, Mu Sigma, Wipro,
What is the difference between near, far and huge pointers?