Aptitude [Subex Placement]: Sample Questions 16 - 17 of 19

Doorsteptutor material for competitive exams is prepared by world's top subject experts: get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 16

Aptitude
Edit

Write in Short

Short Answer▾

What will be the output of following code?

  1. #defineMAX(A , B) ( A <B ? B :A )
  2. #include<stdio.h>
  3. intmain()
  4. {
  5.     inta =MAX( 4+2 , 3×2) ;
  6.     printf(" %d " , a);
  7. }

Explanation

  • Here, MAX function is defined which will give the maximum value between given two. For it ternary operator is used. If A is less then B then B will be the output of MAX function. But if that condition becomes false then output of MAX function will be the value of A.
  • Here, A = 4 + 2 = 6
  • And, B = 3 2 = 6
  • So, MAX (6,6) function is called in the main () function which has integer return type. So 6 > 6 condition is checked and it becomes false because both are equal. If this type of situation occurs then in ternary operator only false part will execute after? . So, value assigned to a will be, a = 3 2 = 6 and it gets printed.

Question 17

Aptitude
Edit

Write in Short

Short Answer▾

What will be the output of the following code?

  1. main()
  2. {
  3.     inta[]={1,2,9,8,6,3,5,7,8,9};
  4.     int ⚹p=a+1;
  5.     intq=a+6;
  6.     printf(“n%d”,q-p);
  7. }

Explanation

  • Here, a is an array of 10 integers, where, a [0] = 1, a [1] = 2, a [2] = 9, a [3] = 8, a [4] = 6, a [5] = 3, a [6] = 5, a [7] = 7, a [8] = 8, a [9] = 9
  • p and q are the integer pointers. In the printf () function we want to print the difference between q and p on the next line which will also be an integer. Here, q - p is evaluated as sizeof (q - p) . q is initialized with a + 6 and p is initialized with a + 1. So, difference between both the integer pointers is five. So, 5 will get printed on the screen.

Developed by: