Passed by reference, an array of values as a function of the parameters

Passed by value (according to a copy of the transfer):

When the arguments passed to a function (parameter), arguments (argument) is not directly transmitted to the function, making twenty first argument value (parameter) copy stored on the stack, and then can be used to make the copy function, rather than using the initial value.

E.g:

#include <stdio.h>
  void change ( int );
  int main () 
 { 
    int num = 9 ; 
    change (NUM);    // the copy num = value of a 9 to change variables, 
    the printf ( " num = D% \ n- " , num); // change the value of a copy, 
     return  0 ;                // num main function does not change with the change function of num becomes 

 } 
void change ( int num) 
{ 
    num ++ ; 
}

operation result:

a = 9

  

Passed by reference:

Refers to when calling the function passes the address of the actual parameters to the function, then the parameters for modification will affect the actual parameters in the function

#include <stdio.h>
  void Change ( int * );
  int main () 
 { 
    int num = . 9 ; 
    Change ( & num);    // pass the address of num 
    the printf ( " num =% D \ n- " , num);
      return  0 ;                

 } 
void Change ( int * num)   // pointer variable, is stored in the main function of an integer variable num address 
{
     * + = num . 1 ;   // * denotes taking the address, the value of the fetch address, point num values, and performing an operation of adding a 
}

   

Array as a function parameter:

 

Guess you like

Origin www.cnblogs.com/18191xq/p/11774335.html