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

How was c created?

0 Answers  


write a program which will count occurance of a day between two dates.

1 Answers   IonIdea,


Define recursion in c.

0 Answers  


What are examples of structures?

0 Answers  


How can I make sure that my program is the only one accessing a file?

0 Answers  






c program to manipulate x=1+3+5+...+n using recursion

2 Answers   Wipro,


what is use#in c

3 Answers  


What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

21 Answers   ADITI, Student, TCS,


How to print India by nested loop? I IN IND INDI INDIA

4 Answers   NIIT, Wipro,


main() { int i; printf("%d",i^i); }

1 Answers  


input may any number except 1,output will always 1.. conditions only one variable should be declare,don't use operators,expressions,array,structure

4 Answers   IBM,


we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?

0 Answers  


Categories