Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created July 27, 2014 07:31
Show Gist options
  • Save adohe-zz/379c492bf1b8dff42bc3 to your computer and use it in GitHub Desktop.
Save adohe-zz/379c492bf1b8dff42bc3 to your computer and use it in GitHub Desktop.
Arguments - Call by Value(C version)
#include <stdio.h>
#include <stdlib.h>
int power(int m, int n);
int main() {
int m, n;
system("clear");
printf("Enter two numbers:\n");
scanf("%d", &m);
scanf("%d", &n);
printf("power(%d, %d) is %d\n", m, n, power(m, n));
getchar();
return 0;
}
int power(int base, int n) {
int p;
for(p = 1; n > 0; n--) {
p = p * base;
}
return p;
}
@adohe-zz
Copy link
Author

In C, all function arguments are passed ``by value.'' This means that the called function is given the values of its arguments in temporary variables rather than the originals. Parameters can be treated as conveniently initialized local variables in the called routine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment