What happens if the following program is executed in C and C++? [code] #include <stdio.h> void main() { printf("Hello World"); } [/code]

What happens if the following program is executed in C and C++?
Code:
#include <stdio.h> 
void main() 
{ 
	printf("Hello World"); 
}
A. Error in both C and C++
B. 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: main() function in C++ must return int otherwise the C++ compiler gives the error whereas C does not forces such things on main() function. Thereas when we aremaking void main(){} function in this program the C++ compiler gives error whereas C compiler runs successfully.
 

Tìm kiếm

Back
Top