This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/Lectures/LC14/PointerFunc2/pointer_function_example_2.c

32 lines
911 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// As we are using the function BEFORE it is actually written we need to provide the
// prototype so that the compiler can verify we are calling it correctly
void CalculateVolumeAndSA ( double Radius, double Length, double *Volume, double *SurfaceArea); // note the *
// This is the main code for our application
int main()
{
double radius = 3.4, length = 7.3, volume, SurfaceArea;
CalculateVolumeAndSA(radius, length, &volume, &SurfaceArea);
printf("The volume is %f \n", volume);
printf( "The surface area is %f\n", SurfaceArea);
return 0;
}
// And here is our function
void CalculateVolumeAndSA ( double Radius, double Length, double *Volume, double *SurfaceArea) // note the *
{
*Volume = M_PI * Radius * Radius * Length;
*SurfaceArea = ( 2 * M_PI * Radius * Radius * Length ) +( 2 * M_PI * Radius * Length );
}