What happens if the following program is executed in C and C++? [code] #include <stdio.h> int main(void) { int new = 5; printf("%d",

Lê Như Ý

New member
What happens if the following program is executed in C and C++?
Code:
#include <stdio.h> 
int main(void) 
{ 
	int new = 5;
	printf("%d", new); 
}
A. Error in both C and C++
B. A successful run in both C and C++
C. Error in C and successful execution in C++
D. Error in C++ and successful execution in C
 
Answer: d
Explanation: new is a keyword in C++, therefore, we cannot declare a variable with name new but as there is no such keyword new in C, therefore, the program is compiled and executed successfully in C.
 

Tìm kiếm

Back
Top