Analysis of the difference between C and C++ parameter free functions

  • 2020-04-02 01:13:12
  • OfStack

The following is a C language function and C++ function to verify this paragraph


# include<stdio.h>
int fun1();
int main()
{
 int a = fun1(3, 4);
 printf("%dn", a);
 return 0;
}
int fun1(int a, int b)
{
 return a + b;
}

There is no problem with the result, the output is 7, so fun() can declare fun(int, int)

# include<iostream>
using namespace std;
int fun1();
int main()
{
 int a = fun1(3, 4);
 cout << a << endl;
 return 0;
}
int fun1(int a, int b)
{
 return a + b;
}

Compile error, "fun1" : the function does not accept 2 arguments. Fun () cannot declare fun(int, int) in C++


Related articles: