recategorized by
706 views

2 Answers

1 votes
1 votes
#include <stdio.h>

int f(int x, int *py, int **ppz) {
	**ppz += 1;
	*py += 2;
	x += 3;
	return x + *py + **ppz;

}

int main() {
	int c = 4;
	int *b = &c;
	int **a = &b;
	printf("%d\n", f(c, b, a));
}

$c$ is passed by value

x is just a local variable of f, it is not same as c,( call by value) while calling the function f, c's value was passed to it, that's it. Any changes to c's ( using its pointer variable) value will not effect x 's value.

$**ppz += 1$ will modify the value of c to 5

$*py += 2$ will modify the value of c to 7

$x = x + 3  = 7$ (local to f )

$x + *py + **ppy = 7 + 7 + 7 = 21$