Methods of Calling Function?
Dec 4, 2011 at 6:55pm Dec 4, 2011 at 6:55pm UTC
Please tell me any two methods of calling the function?
Dec 4, 2011 at 6:59pm Dec 4, 2011 at 6:59pm UTC
if you have function called foo
that takes no arguments you call it by writing foo()
.
Dec 4, 2011 at 8:25pm Dec 4, 2011 at 8:25pm UTC
What exactly do you ask? Can you be more specific?
Dec 4, 2011 at 10:24pm Dec 4, 2011 at 10:24pm UTC
Call by value:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <stdio.h>
#include <stdlib.h>
void swap(int i, int j); //wrong example
int main(){
int i, j;
i = 5;
j = 9;
swap(i, j); //call by value
printf("i=%d j=%d\n" , i, j);
system("pause" );
return 0;
}
void swap(int i, int j){
int temp;
temp = i;
i = j;
j = temp;
}
Call by address:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <stdio.h>
#include <stdlib.h>
void swap(int *i, int *j); //correct example
int main(){
int i, j;
i = 5;
j = 9;
swap(&i, &j); //call by address
printf("i=%d j=%d\n" , i, j);
system("pause" );
return 0;
}
void swap(int *i, int *j){
int temp;
temp = *i;
*i = *j;
*j = temp;
}
Topic archived. No new replies allowed.