当前位置:网站首页>C language -- 17 function introduction
C language -- 17 function introduction
2022-06-22 22:55:00 【Try!】
about “ function ”, The knowledge to be mastered includes the following :
- Definition of function
- Library function
- Custom function
- Function parameter
- Function call
- Nested calls and chained access to functions
- Function declaration and definition
- Function recursion
1、 What is a function ?
In mathematics, we often see the concept of function and use it , Such as f(x)=2x. So in C What is the definition of a function in a language ? How to use it ? In Wikipedia, the definition of function is : Subroutines .( in other words , A subroutine is a function )
- In computer science , Subroutines (subroutine,procedure,function,routine,method,subprogram,callable unit), It's a piece of code in a large program , Consists of one or more statement blocks . It is responsible for completing a specific task , And compared to other code , With relative independence .
- Functions usually have input parameters and return values , Provide encapsulation of the process and hiding of details , These codes are usually integrated into software libraries .

The above figure means that for a function , You need input parameters to get output parameters , Don't pay attention to the implementation process and details of the function when using it , If you know its function, just take it and use it .
2、C Classification of functions in language
C Functions in language are divided into Library function and Custom function .
(1) Library function Why do library functions exist ?
Before we learn C In language programming , You always want to see the results in the print results window after a code is written , At this time, we will frequently use a function , That is to print the information to the screen in a certain format ( This is also printf The function of ); In the process of programming , We may also do some string copying frequently (strcpy); You will also use calculation functions , For example, calculation n Of k Such an operation to the power (pow).
Basic functions like those described above , They are not business code , In the development process, many people may use , In order to support portability and improve program efficiency ,C A series of similar library functions in the basic library of the language , Facilitate software development . Provides several ways to learn library functions 、 website
- cplusplus
- Online tools MSDN
- cppreference Chinese display
C Library functions commonly used in languages - Input and output (IO) function :printf,scanf,getchar,putchar etc.
- String manipulation functions :strcmp,strlen etc.
- Character manipulation functions :toupper function ( Lower case to upper case function )
- Memory manipulation function :memcpy,memcmp,memset etc.
- Time 、 Date function :time etc.
- Mathematical functions :sqrt,pow etc.
- Other library functions
With cplusplus Web site as an example , Introduce how to learn library functionsThere is one thing that needs special attention , That is, using library functions must include #include The header file of a
strcpy: char *strcpy (char *destination, const char *source);

Example 1 :strcpy Function to copy a string , take arr2 Copy content from to arr1 In the middle
#include <stdio.h>
#include <string.h>
int main()
{
char arr1[20] = {
0 };
char arr2[] = "hello,CSDN";
strcpy(arr1,arr2);// take arr2 Copy the contents of to arr1
printf("%s", arr1);// Print arr1 This string %s--- Print in string format
return 0;
}
The operation results are as follows :
hello,CSDN
memset: void *memset(void *ptr,int value,size_t num)

Example 2 :memset function
memory It is translated into memory when translating at ordinary times , It is translated into memory in computer science , therefore memset stay C It is translated into “ Memory settings ”.
int main()
{
char arr[] = "hello CSDN";// Now I want to put arr The first five characters inside are replaced by x
memset(arr,'x',5);
printf("%s",arr);
return 0;
}
Running results :
xxxxx CSDN
(2) Custom function
Library functions don't do everything , It still needs programmers to do some “ Custom function ” To improve the functions required in the program . Custom functions are the same as library functions , All have function names 、 Return value types and function parameters . But the difference is , We need to design these by ourselves .
边栏推荐
- How much do you know about the cause of amplifier distortion?
- A case of 94 SQL optimization (the writing method used is often rejected)
- 2021-04-16
- 2021-07-27
- Palindromes (simple version)
- SQL performance optimization method for interval retrieval
- Redis distributed lock
- 组合总数[标准回溯 + 回溯技巧--降低栈深度]
- 2021-04-14
- Do not know how to choose the development of digital currency wallet?
猜你喜欢

The link added in the bottom menu cannot jump to the secondary page
Task cache compilation caused by gradle build cache

安装typescript环境并开启VSCode自动监视编译ts文件为js文件

Why is yuancosmos so popular? Is the 10trillion yuan shouted by the market boasting or the truth?

2021-05-02

2021-08-21

ArcGIS应用(二十)Arcgis 栅格图像符号系统提示“This dataset does not have valid histogram required for classificati…”

2021-04-05

Practice brings true knowledge: the strongest seckill system architecture in the whole network is decrypted. Not all seckills are seckills!!

What are the methods of software stress testing and how to select a software stress testing organization?
随机推荐
2020-12-04
2021-08-22
Which securities company is the safest and best choice for stock trading account opening
Business stability construction ideas based on Cloud Architecture
Relationship between adau1452 development system interface and code data
Remote access and control - SSH Remote Management and TCP wrappers access control
R language builds a binary classification model based on H2O package: using H2O GLM constructs regularized logistic regression model and uses H2O AUC value of AUC calculation model
The method of making videos of knowledge payment system support m3u8 format playback
Pycharm configuring remote connection server development environment
Technology cloud report: East to West computing is not only about "computing", but also needs "new storage"
[path planning] week 1: hodgepodge
Summary of transport layer knowledge points
5分钟快速上线Web应用和API(Vercel)
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
Greedy interval problem (1)
【ROS】ROSmsg cakin_ Make compilation error
AtCoder abc256全题解(区间合并模板、矩阵快速幂优化dp、线段树……)
In the third week of June, the main growth ranking list (BiliBili platform) of station B single feigua data up was released!
The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
2020-12-20