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

Lâm Phung

New member
What happens if the following program is executed in C and C++?
Code:
#include <stdio.h> 
void func(void)
{
	printf("Hello");
}
void main() 
{ 
	func();
	func(2);
}
A. Error in both C and C++
B. Outputs Hello twice in both C and C++
C. Error in C and successful execution in C++
D. Error in C++ and successful execution in C
 
Answer: a
Explanation: As the func(void) needs no argument during its call, hence when we are calling func(2) with 2 as passed as a parameter then this statement gives the error in both C++ and C compiler.
 

Tìm kiếm

Back
Top