0
return type as (void *) but returning interger value.
Suppose i have a function with fun declaration as: void * foo(int a, int b); But the function definition is as below: //******Function Definition*********// void * foo(int A, int B) { int SUM; SUM = A +B; return SUM; } I call this function in main as below: //******main function***********// int main(void) { int a=10,b=4; int sum; sum = foo(a,b); printf("sum=%d\n",sum); } ///////**********Questions: 1) What will return from the function and what will be the value in "sum" variable in main function? 2) What will be the result if the datatype of "sum" variable is changed to (int*) or (char *) or (char) or anything else? 3) What will be the behavior if i return (&SUM) from "foo" function?
2 Antworten
+ 3
Error. Invalid convertion from int to void*.
Cannot compile.
0
hi @Rrestoring faith ,
I tried the code its working...
please find the working program below:
//code...............
#include <stdio.h>
void * foo(int A, int B)
{
int SUM;
SUM = A +B;
return SUM;
}
int main(void)
{
int a=10,b=4;
int sum;
sum = foo(a,b);
printf("sum=%d\n",sum);
}