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 |
2) Write a program that will help Air Traffic Control for an airport to view the sequence of flights ready for take-off. The airport can accommodate 10 flights waiting for take-off at any point in time. Each flight has a unique 3 digit numeric identifier.  Each time a flight takes-off, Air Traffic Control adds a flight to the waitlist. Each time a flight is added to the waitlist, the list of flights waiting to take-off must be displayed.  When a flight is cleared for take-off, Air Traffic Control removes the flight from the waitlist. Each time a flight takes-off, the list of flights waiting to take-off must be displayed.  Sequence of take-off is the sequence of addition to the waitlist
What are the scope of static variables?
If we have an array of Interger values, find out a sub array which has a maximum value of the array and start and end positions of the array..The sub array must be contiguious. Take the start add to be 4000. For Ex if we have an array arr[] = {-1,-2,-5,9,4,3,-6,8,7,6,5,-3} here the sub array of max would be {8,7,6,5} coz the sum of max contiguous array is 8+7+6+5 = 26.The start and end position is 4014(8) and 4020(5).
5 Answers Microsoft, Motorola,
What does main () mean in c?
How to write a multi-statement macro?
What does. int *x[](); means ?
what is differnence b/w macro & functions
what is the difference between these initializations? Char a[]=”string”; Char *p=”literal”; Does *p++ increment p, or what it points to?
Does * p ++ increment p or what it points to?
Can we replace the struct function in tree syntax with a union?
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
What are the restrictions of a modulus operator?