Skip to content

Instantly share code, notes, and snippets.

@aeonblue3
Created April 11, 2014 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeonblue3/10438937 to your computer and use it in GitHub Desktop.
Save aeonblue3/10438937 to your computer and use it in GitHub Desktop.
#include "stdio.h"
/**
* The purpose of this program is to create two integer variables and assign
* each a value. Then the values are passed to a function that alter their
* values without needint to reference a global variable or returning any
* values.
*
* @author Chris Neitzer
* Discussion Forum 3
*/
/* Prototype for myFunc */
void myFunc(float *argument_one, float *argument_two);
int main()
{
/* Assign integer values to two variables of type integer */
float var_1 = 3.14, var_2 = 6.28;
/* Print out the initial values of the variables */
printf("The value of var_1 was %4.2f and var_2 was %4.2f, ", var_1, var_2);
/* Pass the reference, or pointer, to the two previously declared integer
* variables. */
myFunc(&var_1, &var_2);
/* Now, print out the altered values of the two variables declared at the
* beginning of the main function. */
printf("but now var_1 is %4.2f and var_2 is %4.2f!\n", var_1, var_2);
fflush(stdin); /* clear input area so you can pause */
printf("Press the key to exit program.");
getchar(); /* force the computer to pause until you press a key on the keyboard */
return 0;
}
/**
* myFunc accepts two integer pointers as arguments and assigns new values to
* them.
*/
void myFunc(float *argument_one, float *argument_two)
{
*argument_one = 41.3;
*argument_two = 82.6;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment