Created
October 21, 2010 21:16
-
-
Save davidphasson/639381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
void avg_pbr(int a, int b, int *r); | |
int avg(int b, int a); | |
int main() | |
{ | |
int *result; | |
int res; | |
int res2; | |
// Pass the values | |
res = avg(5, 15); | |
printf("Norm: %d\n", res); | |
// Pass a pointer | |
avg_pbr(15, 25, result); | |
printf("Address: %p\n", result); | |
printf("By ptr: %d\n", *result); | |
// Pass by reference | |
avg_pbr(25, 35, &res2); | |
printf("Address: %p\n", &res2); | |
printf("By ref: %d\n", res2); | |
return 0; | |
} | |
int avg(int a, int b) | |
{ | |
return (a+b)/2; | |
} | |
void avg_pbr(int a, int b, int *r) | |
{ | |
*r = (a+b)/2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment