#include <stdio.h> int Fun ( int n-, int S) {// is the number of n-sum of the number, s is the return number, which is the initial value 0 IF (n-<= 0 ) { return 0 ; // number of parameters is less than or equal to zero, terminates the S = 0 ; } the else { for ( int I = 1 ; I <= n-; I ++) // number is not 0, the 1 + 2 + 3 .. . ... S = S + I; return . 1 ; } } main ( void ) { int A = . 3 , B = 0 ; IF (Fun ( 2 , 0 )) the printf ( " % D \ n- ' , B); the else the printf ( " Parameter error " ); }
The above procedure is just a function is defined, in the main function was carried out calls for b assignment, but did not return, so the result is the initial output value of b 0.
#include <stdio.h> int Fun ( int n-, int & S) { IF (n-<= 0 ) { return 0 ; // number of parameters is less than or equal to zero, terminates the S = 0 ; } the else { for ( int I = . 1 ; I <= n-; I ++) // number 0 is not performed. 3 + 2 + .... 1 ... S = S + I; return . 1 ; } } main ( void ) { int A = . 3 , B = 0 ; IF(Fun (A, B)) the printf ( " % D \ n- ' , B); the else the printf ( " Parameter error " ); }
After the front of the parameter s together with an ampersand, again when the output of the second argument, the result is correct.
I.e.: parameters form b after performing retain their value, the value back to the argument. For not a reference type parameter can be added to achieve & return parameters.