Hi all,
MY first post :)
Am not sure why am getting the following errors.The program seems fine..
Quote
C:\Users\Ryuzaki!.Vegeta-PC.000\Desktop\Programs\Lab\FunAndSwiCase.c(18): error #2168: Operands of '=' have incompatible types 'int __cdecl function(int, int)' and 'int'.
C:\Users\Ryuzaki!.Vegeta-PC.000\Desktop\Programs\Lab\FunAndSwiCase.c(18): error #2088: Lvalue required.
C:\Users\Ryuzaki!.Vegeta-PC.000\Desktop\Programs\Lab\FunAndSwiCase.c(19): error #2060: Invalid return type; expected 'int' but found 'int __cdecl (*)(int, int)'.
Heres the code:
#include<stdio.h>
int sum(int ,int );
int main(void)
{
int a,b,result;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
result=sum(a,b);
printf("The result of the two is %d\n",result);
return 0;
}
int sum(int x,int y)
{
sum=x+y;
return(sum);
}
int sum(int x,int y)
{
sum=x+y;
return(sum);
}
You cannot use the function name as a variable, it is a function of type int _cdecl sum
This will work...
int sum(int x,int y)
{
int ret;
ret = x+y;
return ret;
}
As a rule you should not create variables execpt when you need them so...
You can do this...
int sum(int x,int y)
{
return x+y;
}
Yea....ofc...my bad.Thanks.