So I was trying to print the result of a function from main, but for some reason, I get the error signal: segmentation fault (core dumped)
. My program is supposed to calculate all of the expressions by reference, and call and print the result from main()
.
here's the code:
#include <math.h>
#include <stdio.h>
void prodDivPowInv(float a, float b, float *prod, float *div, float *pwr, float *invb);
int main() {
float x, y;
scanf("%f", &x);
scanf("%f", &y);
float *prod_1, *div_1, *pwr_1, *invb_1;
prodDivPowInv(x, y, prod_1, div_1, pwr_1, invb_1);
printf("product=%f\n", *prod_1);
printf("division=%f\n", *div_1);
printf("power b of a=%f\n", *pwr_1);
printf("inverse of b=%f\n", *invb_1);
return 0;
}
void prodDivPowInv(float a, float b, float *prod, float *div, float *pwr,
float *invb) {
(*prod) = a * b;
(*div) = a / b;
(*pwr) = pow(a, b);
(*invb) = 1 / b;
}