Skip to content

Instantly share code, notes, and snippets.

@davidphasson
Created October 21, 2010 21:16
Show Gist options
  • Save davidphasson/639381 to your computer and use it in GitHub Desktop.
Save davidphasson/639381 to your computer and use it in GitHub Desktop.
#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