Defined functions, and call
/ * Call functions * / #include <stdio.h> void FUNC ( void ) { the printf ( " . 1 \ n- " ); } int main () { FUNC (); return 0 ; }
Using the return value using a function defined in the operation int func (void)
/ * Return value returned Demo * / #include <stdio.h> int Read ( void ) { static int Val = 0 ; the printf ( " Enter a number: " ); Scanf ( " % D " , & Val); return Val; } int main () { int Val = Read (); the printf ( " the number you entered is D% \ n- " , Val); }
Parameter input function void func (int val, int val1)
/* 输入参数演示 */ #include <stdio.h> void read(int val, int val1) { printf("%d x %d = %d\n", val, val1, val * val1); } int main() { int tmp = 0; for (tmp = 1;tmp <= 5;tmp++) { read(tmp, 10 - tmp); } }
In function, using the operation input array parameters
/ * Printing operation arrays * / #include <stdio.h> void Print ( int ARR [], int size) { int tmp = 0 ; for (tmp = 0 ; tmp <size; tmp ++ ) { the printf ( " % D " , ARR [tmp]); } the printf ( " \ n- " ); } int main () { int ARR [ . 5 ] = { . 1 , 2 , . 3 , . 4 , . 5 }; print(arr, 5); }
In function of the input array for operation because the input address of the array is represented, the return value may not be required
/ * The array into negative * / #include <stdio.h> void NEG ( int ARR [], int size) { int Val = 0 ; for (Val = 0 ; Val <size; Val ++ ) { ARR [Val] = 0 - ARR [Val]; } } int main () { int ARR [ . 5 ] = { . 1 , 2 , . 3 , . 4 , . 5 }; NEG (ARR, . 5 ); for (int val = 0;val < 5;val++) { printf("%d ", arr[val]); } printf("\n"); }