Write the output of the following program: int a[ ] = {1,2,3,} *p;

int a[] = {1,2,3,} *p;
                        

Options

  • A. Junk value
  • B. 3
  • C. Runtime error
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

E. None of the above

Detailed Explanation

Correct Answer: None of the above.

The given statement is not a complete executable program. It contains an array declaration and a pointer declaration, but the pointer p is not initialized to any valid memory address and no operation is performed that would produce an output.

The array contains the values 1, 2 and 3, but this does not mean that the output will automatically be 3. Similarly, an uninitialized pointer does not automatically produce a specific runtime error in this incomplete statement.

Therefore, among the given choices, None of the above is the appropriate answer.

Exam point: An array declaration and a pointer declaration alone do not produce output. A pointer must be assigned a valid address before it is safely dereferenced.