. Advertisement .
..3..
. Advertisement .
..4..
Good moring everybody.
I’m getting the ”too few arguments to function c++” error when running my program.
#include <stdio.h>
int sum(int a, int b, int c)
{
return (a+b+c);
}
int main()
{
int x,y,z;
x = 10; y = 20; z = 30;
printf("sum = %d\n", sum(x, y));
printf("sum = %d\n", sum(x));
printf("sum = %d\n", sum(10, 20));
return 0;
}
And then it gives me the output:
prog.c: In function ‘main’:
prog.c:12:23: error: too few arguments to function ‘sum’
printf("sum = %d\n", sum(x, y));
^~~
prog.c:3:5: note: declared here
int sum(int a, int b, int c)
^~~
prog.c:13:23: error: too few arguments to function ‘sum’
printf("sum = %d\n", sum(x));
^~~
prog.c:3:5: note: declared here
int sum(int a, int b, int c)
^~~
prog.c:14:23: error: too few arguments to function ‘sum’
printf("sum = %d\n", sum(10, 20));
^~~
prog.c:3:5: note: declared here
int sum(int a, int b, int c)
^~~
prog.c:9:10: warning: variable ‘z’ set but not used [-Wunused-but-set-variable]
int x,y,z;
^
Can someone help me to fix the problem?
The cause: This error happens because there are differing numbers of formal and actual arguments.
Solution: You must check the total number of arguments while calling a function.
Output: