Microsoft
Company
Programming
Program
#include
#include
#define MAX(x,y) (x)>(y)?(x):(y)
int main()
{
int i=10;
int j=5;
int k=0;
k=MAX(i++,++j);
printf("
%d %d %d",i,j,k);
return 0;
}
Read Solution (Total 25)
-
- i=12 ,j=6 ,k=11
- 10 years agoHelpfull: Yes(12) No(4)
- i=11,j=6,k=10
- 10 years agoHelpfull: Yes(9) No(3)
- The macro MAX(x,y) returns the biggest num of two given nums
k=MAX(i++,++j) becomes
k=(i++)>(++j)?(i++):(++j);
k=(10)>(6)?(11):(6); // here i becomes 12
now k is 11,i is 12,j is 6
- 9 years agoHelpfull: Yes(8) No(0)
- Max(x,y) will return the greater value b/w x and y
k=MAX(i++,++j) will return 10 because i++=10 and ++j=6 during k=MAX(i++,++j) so k=i++=11
after the execution of this statement i will be 12
so result will be 12,6,11 - 9 years agoHelpfull: Yes(5) No(0)
- output: 12 6 11
max(i++,j++)----->(i++)>(++j) ? (i++) : (++j)
i incremented for two times because condition is true
i++ is postincrement so k will get only 11 - 9 years agoHelpfull: Yes(3) No(0)
- i=12 j=6 k=11
- 10 years agoHelpfull: Yes(2) No(0)
- the correct answer is i=12,j=6,k=11 (tested on turbo c)
can anyone provide me reason for the answer? - 9 years agoHelpfull: Yes(2) No(0)
- i=12, j=6, k=11 as
if ( i++ > ++j )
then i++;
else ++j
since i is greater than j so if block will execute and increments i two times. first when checking condition and second while executing if block... while j is incremented only once while checking the condition. - 9 years agoHelpfull: Yes(2) No(0)
- i=10,j=5,k=10
- 10 years agoHelpfull: Yes(1) No(3)
- i=12,j=6,k=12
- 9 years agoHelpfull: Yes(1) No(1)
- wont even compile since nothing is included
- 9 years agoHelpfull: Yes(1) No(4)
- can anyone pls explain why i is 12
- 9 years agoHelpfull: Yes(1) No(0)
- ans:
i=11,j=5,k=11 - 10 years agoHelpfull: Yes(0) No(5)
- 10,6,11 since i is the bigger value its value will be returned by the max function and will be incremented because i++ is sent..
- 9 years agoHelpfull: Yes(0) No(3)
- i=10,j=6,k=11
- 9 years agoHelpfull: Yes(0) No(1)
- i=11,j=6,k=10 (from turbo c)
- 9 years agoHelpfull: Yes(0) No(2)
- i=11 ; j=6; k=10
- 9 years agoHelpfull: Yes(0) No(2)
- i=10 , j=5 , k=11
since there is increments in i and j just to set value for j, but overall there is no change in i and j. - 9 years agoHelpfull: Yes(0) No(1)
- 10,6,10...due to post increment operator value of i remains same till execution of max while i is associated with predecrement operator so it's value is increment before execution of max
- 9 years agoHelpfull: Yes(0) No(1)
- Answer is I=10,j=6,k=10.. because k calls the macro MAX in which its to find maximum number..and I is not incremented but j is incremented
- 9 years agoHelpfull: Yes(0) No(1)
- it will print 11,6,10
- 7 years agoHelpfull: Yes(0) No(1)
- 11,6,10
because k=MAX(10,6);
here control moves to MAX(x,y) function where 10 > 6 ,therefore k=10;
hence for post-increment of i takes place,it takes the original value and then increments it,in the final print statement i,j,k are 11,6,10 respectively - 6 years agoHelpfull: Yes(0) No(0)
- 11 ,6 , 10
- 6 years agoHelpfull: Yes(0) No(0)
- i=12,j=6,k=11
- 6 years agoHelpfull: Yes(0) No(0)
- i=12, j=6, k=11
after execution (i++) >(++j) ? (i++) :(++j)// 10>6? (i++)10:6 is become as k=MAX(i++=11, ++j=6)
again execution of K=MAX(i++, ++j) K= 11 and i=12 because in MAX(i++ is post increment).
hence i=12, j=6 ,k=11 - 3 years agoHelpfull: Yes(0) No(0)
Microsoft Other Question