C Language Basics Tutorial (v) functions (2)

Source: Internet
Author: User
Tags function definition header what header

1. Description and definition of function
All functions in the Turbo C2.0, like variables, must be described before they are used. A description is a function of what type of function, the description of the general library function is contained in the corresponding header file <*.h>, for example, the standard input-output function is contained in stdio.h, and the nonstandard input-output function is contained in the io.h. Later, when you use a library function, you must first know what header file The function is contained in, and use the #include <*.h> or #include "*.h" description at the beginning of the program. Only in this way the program is compiled, connected to the turbo C to know it is provided by the library function, otherwise, it will be considered as a user-written function and can not be assembled.
1.1 Function Description
1. The classic way
Its form is the:  function type   function name ();
2. ANSI mode
is in the form of:  function type   function name (data type   formal parameter,  data type   form
parameter, ...);
Where: The function type is the data type of the return value of the function. This can be an integer (int) that was previously introduced, a long integer, a character type (char), a single floating-point type (float), a double floating-point type (double), and no value type (void), or a pointer, including a structure pointer. A value-less representation function has no return value. The
function is named the identifier of the turbo C2.0, and the contents of the parentheses are descriptions of the formal parameters of the function. You can have only data types without formal parameters, or both. There is no parameter information for the classical function description. For example,
int putlll (int x,int y,int z,int color,char *p)/* Describes an integer function */
char *name (void);  /* describes what a string refers to function/
void St udent (int n, char *str); /* Description of a function that does not return a value */
float calculate ();  /* description of a floating-point function/
Note: If a function is invoked without a description, the compiler does not think it is an error and defaults to the integer (int) function. So when a function returns other types without first stating it, the compile will be an error.
1.2 Function Definitions

A function definition is a subroutine that determines what function the function completes and how it runs, equivalent to another language. The Turbo C2.0 defines the function by the ANSI method. That
function type function name (data type form parameter; Data type form parameter ...)
{
function body;
}
The data type of the function type and the formal parameter is the basic data type of the Turbo C2.0. The function body is a combination of library functions and statements provided by the Turbo C2.0 and other user-defined function call statements, and is included in a pair of curly braces "{" and "}".
It should be noted that a program must have a main function, other user-defined child functions can be any number of functions, the location of the function is not any restrictions, can be in front of the main () function, can also be followed. The Turbo C2.0 all functions are considered to be global. And it is external, that is, it can be called by any one of the functions in another file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.