What happens if the following line is executed in C and C++? [code] const int a; [/code]

Như Quỳnh

New member
What happens if the following line is executed in C and C++?
Code:
const int a;
A. Error in both C and C++
B. Warning 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: C++ compiler does not allow the programmer to declare a constant variable without initializing it hence the C++ compiler gives an error whereas C allows such declaration, therefore, the program compiles and runs successfully.
 

Tìm kiếm

Back
Top