What happens if the following program is executed in C and C++? int new=5; printf("%d", new);

Options

  • A. Error in C and successful execution in C++
  • B. Error in both C and C++
  • C. Error in C++ and successful execution in C
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Error in C++ and successful execution in C

Detailed Explanation

Answer: (C) Error in C++ and successful execution in C

In C, new is not a reserved keyword, so it can be used as an identifier. Therefore, int new = 5; is valid C code.

In C++, new is a reserved keyword used for dynamic memory allocation. Therefore, it cannot be used as a normal variable name.

Important: The question is testing the difference between C and C++ keywords. If the code is literally written as intnew=5; without a space, it is an undeclared identifier and would produce an error. The intended TRE-3 question is clearly based on int new = 5;.