What happens if the following program is executed in C and C++?

#include <stdio.h> 
void func(void)
{
    printf("Hello");
}
void main() 
{ 
    func();
    func(2);
}

a) Outputs Hello twice in both C and C++
b) Error in C and successful execution in C++
c) Error in C++ and successful execution in C
d) Error in both C and C++

1 thought on “What happens if the following program is executed in C and C++?”

  1. d
    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.

Leave a Comment