Open In App
Related Articles

A C/C++ Function Call Puzzle

Improve Article
Improve
Save Article
Save
Like Article
Like

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. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 10 Jun, 2022
Like Article
Save Article
Similar Reads