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



main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / revathi

Correct Answer is 3.

Do not post wrong answer.

Is This Answer Correct ?    1 Yes 0 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

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

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / gowtham

complier error

Is This Answer Correct ?    13 Yes 14 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / aniruddha

It will print answer 1 because in case of++ atfairt assing
and then increment..

Is This Answer Correct ?    5 Yes 6 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

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

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

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

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / lukz

4 is output

Is This Answer Correct ?    2 Yes 7 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / abdur rab

it will lead to Undefined behaviour, both answers 3 aand 4
are correct.

Is This Answer Correct ?    0 Yes 5 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / ssssssssss

output
2

Is This Answer Correct ?    1 Yes 6 No

main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i])..

Answer / raju

correct answer is 2 bcz once assign only that will take as
that value

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C Interview Questions

Input any no. and print all the the numbers that comes before it like this for e.g input = 4 0 01 012 0123 01234 plz answer it 2day

3 Answers  


What is size of union in c?

0 Answers  


What are the types of variables in c?

0 Answers  


What is the basic structure of c?

0 Answers  


what is difference between c and c++

4 Answers  






Hai friends im a i year student. i want to develop my knowledge in the field of TSR in c. How I'm Improve ?

2 Answers  


main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Find the Outputs?

9 Answers   BTBP, CitiGroup,


What is a pragma?

0 Answers  


write a program to sum of its digit with using control structure or with out using loop. for ex: let the number is 25634 then answer will be=2+5+6+3+4=20

4 Answers  


What is the use of linkage in c language?

0 Answers  


Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17

0 Answers  


Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) function.

2 Answers  


Categories