-
-
Save adohe-zz/379c492bf1b8dff42bc3 to your computer and use it in GitHub Desktop.
Arguments - Call by Value(C version)
This file contains 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 <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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.