When we wanna return one particular type of data, we need to declare a global variable first right? and assign this variable to the value thats being returned by the funtion?
Also for int primitive data type, we cannot use malloc to reserve memory block?
Sincerely, headful of doubts.
#include <math.h>
#include <stdio.h>
int *sum();
int main()
{
int *num;
num = sum();
printf("\nSum of two given values = %d", *num);
return 0;
}
int *sum()
{
int a = 50, b = 80;
int *sum = NULL;
printf("%d %d",a,b);
*sum = a+b;
return sum;
}
I wanna using pointers to save the data thats being returned by the function. is it possible? I know it's possible for linked list structures. But I'm not sure about integers and other primitive data types.
malloc, yes, you can use it with primitives:int *sum = malloc(sizeof(*sum));int main(void)