All mock tests are FREE till 31 December — register to save your progress
Unit 3 · Programming Languages and Computer Graphics Paper 2 CS · June 2024 (Cancelled Exam)

What is the output of the following C program?
#include <stdio.h>
int main(void) {
  int x, *p;
  x = 30;
  p = x;
  printf("%d", *p);
  return 0;
}

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. Error

Explanation

p = x assigns an int to a pointer (it should be p = &x). This is a constraint violation, and dereferencing address 30 is invalid, so the result is an error.

More Programming Languages and Computer Graphics questions