The GATE Grind

GATE 2024 CS (CS2) – Question 36

Programming and Data Structures · Programming in C · 2 marks · Multiple choice

What is the output of the following C program?

#include <stdio.h>
int main() {
 double a[2]={20.0, 25.0}, *p, *q;
 p = a;
 q = p + 1;
 printf("%d,%d", (int)(q - p), (int)(*q - *p));
 return 0;}
  1. 4,8
  2. 1,5
  3. 8,5
  4. 1,8

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 1,5

Explanation

Pointer subtraction gives element count: q − p = 1. Value difference is 25.0 − 20.0 = 5. Output: 1,5.