Methods of Calling Function?

Please tell me any two methods of calling the function?
if you have function called foo that takes no arguments you call it by writing foo().
What exactly do you ask? Can you be more specific?
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.