I was playing around with function pointers in C just to learn. I tried calling a void function and setting its result to an int.
void function(int x, int y){
printf("%d,%d\n",x,y);
}
int main(){
int (*fptr)(int,int);
fptr = function;
int a = fptr(2,3);
printf("%d\n",a);
return 0;
}
The output I get from this is:
2,3
4
After playing around with this a little, I realized that main is printing the number of characters in the printf statement in function(). Why is this happening? Is this expected output?
printfsince that's what's left in the accumulator when the function returns (printfwas the last thing called and it does have a return value). But it's not guaranteed. You can't count on it. So is it expected? No. Is it explainable? Yes.ais before and after the call. Probably the same.