-
Call-by-value
Passing the value to a function as a parameter. If the function modifies the variable, the actual variable won’t get changed.
void fun1(int myParam) { myParam = 4; } void main() { int myValue = 2; fun1(myValue); printf("myValue = %d",myValue); }
myValue
will always be 2. -
Call-by-address (pointer)
void fun1(int *myParam) { *myParam = 4; } void main() { int myValue = 2; fun1(&myValue); printf("myValue = %d",myValue); }
Here we are passing the address of
myValue
tofun1
. So the value ofmyValue
will be 4 at the end ofmain()
. -
Call-by-alias
There is no alias in C as per my understanding. It should be the C++ reference mechanism.
-
Global variable / Static variable
Global and static variables are variables stored in a common places, accessible by the caller and callee functions. So both caller and callee will be able to access and modify them.
int myValue = 2; void fun1() { myValue = 4; } void main() { myValue = 2 fun1(); printf("myValue = %d",myValue); }
As you can guess, the value of
myValue
will be 4 at the end ofmain()
.
Hope it helps.