Without malloc()
in sum_retbyptr()
, the below program works well. Why it does not have error?
gcc -v 10.3.0 on Linux
#include <stdio.h>
int *sum_retbyptr(int*, int*);
int main(){
int a = 20, b=30, res;
res = *sum_retbyptr(&a, &b);
printf("Data transfer by return by ref : %d\n", res);
return 0;
}
int *sum_retbyptr(int* a, int* b){
int* ptr;
// ptr = malloc (sizeof(int));
*ptr = *a + *b;
return ptr;
}