Introduction
Information can be passed from one function to another using parameters.
Program
main ( ) { int i; i = 0; printf (" The value of i before call %d \n", i); f1 (i); printf (" The value of i after call %d \n", i); } void f1 (int k) { k = k + 10; }
Explanation
-
The parameter used for writing the function is called the formal parameter, k in this case.
-
The argument used for calling the function is called the actual parameter.
-
The actual and formal parameters may have the same name.
-
When the function is called, the value of the actual parameter is copied into the formal parameter. Thus k gets the value 0. This method is called parameter passing by value.
-
Since only the value of i is passed to the formal parameter k, and k is changed within the function, the changes are done in k and the value of i remains unaffected.
-
Thus i will equal 0 after the call; the value of i before and after the function call remains the same.
3 comments:
can you make c for hardware
YEs I Like
Post a Comment