A C/C++ Function Call Puzzle

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

filter_none

edit
close

play_arrow

link
brightness_4
code

void func()
{
    /* definition */
}
  
int main()
{
    func();
    func(2);
}

chevron_right


The above program compiles fine in C, but doesn’t compiler 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 compiler by Rahul Mittalal. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


7


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.