From 3d18a567244e12d5a510317a5f4acb4cab5e3526 Mon Sep 17 00:00:00 2001 From: Steven Schronk Date: Tue, 24 Nov 2009 19:10:46 -0600 Subject: [PATCH] Added program that illustrates passing data by value and by address --- double.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 double.c diff --git a/double.c b/double.c new file mode 100644 index 0000000..2aa85d6 --- /dev/null +++ b/double.c @@ -0,0 +1,47 @@ +#include + +void doubleData( float x, float y); +void doubleDataByAddress( float *x, float *y); + +main() +{ + + float x = 10.0; + float y = 5.0; + + printf("First Arg: %f\n", x); + printf("Second Arg: %f\n", y); + + + doubleData(x, y); + + printf("First Arg: %f\n", x); + printf("Second Arg: %f\n", y); + + + doubleDataByAddress(&x, &y); + + printf("First Arg: %f\n", x); + printf("Second Arg: %f\n", y); + + return 0; + +} + +void doubleData( float x, float y) +{ + x *= 2.0; + y *= 2.0; + printf("First Arg: %f\n", x); + printf("Second Arg: %f\n", y); +} + +void doubleDataByAddress( float *x, float *y) +{ + *x *= 2.0; + *y *= 2.0; + printf("First Arg: %f\n", *x); + printf("Second Arg: %f\n",* y); +} + + -- 2.11.4.GIT