我试图理解指针和void函数,我只学习了9周的C语言,而函数却让我有些头疼。关于为什么我在printf()
调用指针* result
#include <stdio.h>
#include <math.h>
/*Declare remainder functions*/
double getRemainder1(double, double);
void getRemainder2(double, double, double *result);
int main()
{
/*Declare variables*/
double num1, num2, result;
/*User input*/
printf("Enter your two numbers (1-100)? ");
scanf("%lf%lf", &num1, &num2);
/* function call*/
result = getRemainder1(num1,num2);
printf("The remainder of %.2lf and %.2lf using the getRemainder1 function is %.2lf\n",num1, num2, result);
printf("The remainder of %.2lf and %.2lf using void getRemainder2 function is %.2lf\n",num1, num2, *result);
return 0;
}
void getRemainder2(double num1,double num2,double *result)
{
*result = fmod(num1,num2);
return;
}
double getRemainder1(double num1,double num2)
{
double result;
result = fmod(num1,num2);
return result;
}