Introduction to Functions
Problems encountered:
1. The code looks very much, not concise
2. The change is very troublesome, need to all use of place to revise
function can solve these two problems
Function can be understood as a packing belt, that is, to package a piece of code, when used, just write the name of the packing belt.
Classification of functions:
1. Functions without parameters and no return value
2. Function with parameters
3. Functions with Return values
The definition syntax for a function without a parameter without a return value:
void function name () {
function body;
}
Meaning: The function name is your own name, but to conform to the identifier specification:
1. To make a name meaningful, you have to know what you mean by looking at it.
2. Only the following lines, letters, and $, followed by underscores, numbers, letters,
3. Cannot use keywords as names
4. Observe the Hump naming method: First letter lowercase, each subsequent word capitalized
The function body is the code to be packaged
Call syntax for the function:
The call means that you need to use this bundled code somewhere.
Grammar:
function name ();
Example: Drawheart ();
Tips: Code examples are as follows
#include <stdio.h>
void Drawheart () {
printf ("Hibiscus, 5201314\n");
printf ("* * * * * * *****\n");
printf ("********* *********\n");
printf ("************ ************\n");
printf ("***************************\n");
printf ("***************************\n");
printf ("***************************\n");
printf ("*************************\n");
printf ("*********************\n");
printf ("*****************\n");
printf ("*************\n");
printf ("*********\n");
printf ("*****\n");
printf ("***\n");
printf ("*\n");
}
int main (int argc, const char * argv[]) {
Drawheart ();
return 0;
}
Introduction to the function of C language