Sasken Papers: Sample Questions 35 - 35 of 35

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

Question number: 35

» Aptitude

Short Answer Question▾

Write in Short

What is the output of the Program?

  1. main ()
  2. {
  3.     int a[10] = { 12345678910};
  4.     int *p = a;
  5.     int *q = & a[9];
  6.     printf ( “%d” q - p + 1);
  7. }

Explanation

  • Here, a is an array of 10 integers, where, a [0] = 1, a [1] = 2, a [2] = 3, a [3] = 4, a [4] = 5, a [5] = 6, a [6] = 7, a [7] = 8, a [8] = 9, a [9] = 10
  • p and q are the integer pointers. In the print f () 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 size of (q – p). q is initialized with a + 0 and p is initialized with a + 9. So, difference between both the integer pointers is 9. So, q – p + 1 = 9 + 1 = 10 will get printed on the screen.
  • Output is 10