Open In App

A C/C++ Function Call Puzzle

Last Updated : 10 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Consider the following program. Predict the output of it when compiled with C and C++ compilers.

C




#include<stdio.h>
 
void func()
{
    /* definition */
}
 
int main()
{
    func();
    func(2);
}


C++




#include <iostream>
using namespace std;
 
void func()
{
    /* definition */
}
 
int main() {
    func();
    func(2);
 
    return 0;
}


The above program compiles fine in C, but doesn’t compile in C++.

In C++, func() is equivalent to func(void) 
In C, func() is equivalent to func(…)

Refer this for details and this for more programs that compile in C, but not in C++.

This article is compiled by Rahul Mittalal.
 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads