Subex Papers: Sample Questions 3 - 4 of 19

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 3

» Aptitude

Short Answer Question▾

Write in Short

What will be the output of the following code?

  1. main()
  2. {
  3.     int x=128;
  4.     printf("n%d",1+x++);
  5. }

Explanation

  • Here, one integer variable x is initialized in the main () function with 128. In the printf function we can write those things which we want to get printed on screen. Here, is the escape sequence for new line. %d is the format specifier for integer variables. x++ is the post increment operator on x. In post increment operator first value of variable is assigned to the assignment operator and then value of variable gets incremented by 1.
  • So, (1) + (x++) = 1 + x = 1 + 128 = 129
  • And 129 will be printed as output on the next line of screen.
  • Now value of variable x is incremented by 1 and becomes 129.

Question number: 4

» Aptitude

MCQ▾

Question

What will be the output of following code?

  1. main()
  2. {
  3.     int i=0;
  4.     if(i==i++)
  5.     return1;
  6.     else
  7.     return0;
  8. }

Choices

Choice (4) Response

a.

Always 1

b.

Always 0

c.

None of the above

d.

Question does not provide sufficient data or is vague

Answer

a.

Explanation

  • Here, one integer variable is initialized with 0. In the next statement if condition is checked, where if i == i++ then 1 will get returned from the if loop and if condition is not satisfied then else part will get executed and it will return 0.
  • In the condition i++ is post increment of variable i i. e first assign the value and then increment it’s value by 1. So, i and i++ will have same values and condition in the if statement will be true. So it will always return 1.