This is my simple C program.
#include <stdio.h>
float*multiply(int, float);
main(){
int i =3;
float f = 3.50, *p;
p = multiply(i, f);
printf("%u\n", p);
printf("%f\n", *p);
return 0;
}
float *multiply(int ii, float ff){
float product = ii * ff;
printf("%f\n", product);
printf("%u\n", &product);
return (&product);
}
This program gives the following output:-
But, when I comment out the two "printf" statement in multiply
function, It gives the following output:-
I am really sure I'm not doing any silly mistake. I am just commenting out two lines.
Can anyone tell me why is this happening? Is this OS/System related problem?
How is printf
function increasing the life of the variable?