#include <stdio.h>
int add2nums( int, int);
void main(void)
{
int y,a,b;
printf("Enter 2 numbers\n");
scanf("%d%d", &a, &b);
y = add2nums(a,b);
printf("a is %d\n", a);
printf("b is %d\n", b);
printf("y is %d\n", y);
}
int add2nums( int num1, int num2)
{
int sum;
sum = num1 + num2;
return(sum);
}
So usually, when I create new functions in C the definition of the function is created before the main()
function.
In my lecture, there is this example of how to create a function prototype and how they are created by declaring it before the main()
function and then defining it after the end of the main()
function.
When running the program above, the following error comes up:
Line5: warning: return type of 'main' is not 'int' [-Wmain]|
What is happening? And why is the declaration of the function add2nums()
occur twice once before main()
and with no parameters?
int add2nums( int, int);
and then again after the end of main()
with parameters num1
and num2
int add2nums( int num1, int num2)