blogger Indonesia

Follow judhyns blog

PARAMETER PASSING

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

  1. The parameter used for writing the function is called the formal parameter, k in this case.

  2. The argument used for calling the function is called the actual parameter.

  3. The actual and formal parameters may have the same name.

  4. 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.

  5. 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.

  6. Thus i will equal 0 after the call; the value of i before and after the function call remains the same.

Points to Remember

  1. C uses the method of parameter passing by value.

  2. In parameter passing by value, the value before and after the call remains the same.

3 comments:

Anonymous said...

can you make c for hardware

Sirajudin Saleh said...
This comment has been removed by the author.
Sirajudin Saleh said...

YEs I Like

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |