当前位置:网站首页>Detailed explanation of C language knowledge points -- first knowledge of C language [1]
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
2022-04-23 14:28:00 【VelvetShiki_ Not_ VS】
C language ⾔
C Language is a process oriented programming language , Applied to the underlying development , Unlike object-oriented programming languages ( Such as C++,JAVA), Many high-level languages or operating systems, such as python,C++,Linux It's all based on C Based on .C Language can be compiled in a simple way 、 Processing low-level memory , It only produces a small amount of machine language and efficient programming language that can run without any running environment support .
C standard
from ANSI C By the American National Standards Institute (ANSI) And the international organization for Standardization (ISO) About C The standard of language . current C11 The standard is C The third official standard of language , The standard better supports Chinese character function names and Chinese character identifiers , To a certain extent, Chinese character programming is realized . Now commonly used by the public C The standard is C99.
Main compiler
MSVC, GCC, Sublime, Turbo C, Clang etc. .
VS2022: Slightly different from the compiler , It is an integrated editor , compiler (MSVC) An easy-to-use integrated development environment integrated with debugger .
General steps for editing code and running
- Preparation before compiling :
① Create a new project —— Generate empty project (C++), The project name shall be in English , There should be no spaces or special characters between characters , Store to a specific disk location .
② Create the source file ——C yes C++ A subset of languages ,C++ The powerful functions contained in C File formats are also compatible , So choose C++ File creation format .
2. The basic composition of the code
① Introduction of header file : The header file contains a lot of C Library functions , These library functions are C The language compiler itself exists C The language library function is used by the underlying developers in the development , Higher frequency functions are encapsulated , Put it in a header file in advance , For all programmers . When using, the format is usually used at the beginning of the source file #include< file name .h> Import header file , Common header files and their functions :
⑴#include<stdio.h>: The standard I / O header file defines three variable types ( Unsigned integer size_t, file type FILE, Any location or type where files are stored fpos_t), Some macros ( Null value NULL, End of file flag EOF etc. ) And various functions to perform input and output ( If the file is opened fopen, Format output fprintf, Stream buffer definition setbuff etc. ).
⑵#include<stdlib.h>: The utility header file defines some common macros and tool functions ( Such as dynamic development of memory malloc, Free memory free, Random number generation rand etc. )
⑶#include<string.h>: Defines how to manipulate the header file of the character array .
⑷#include<math.h>: Header files related to mathematical operations and operations .
⑸#include<windows.h>: Header files related to operating system instructions .
wait
② The main function —— Declaration of main function int main(void), yes C Language agreed program execution entry , Parentheses are void Omission . The standard format is int main(int argc, char* argv[]), The former is the number of parameters passed , The latter is the parameter value , But it's temporarily empty void that will do .int Is an integer value , Indicates that the return value of the main function of the code is an integer variable int, The general main code is the main carrier for the integration and function realization of user-defined functions , So the return value at the end is usually return 0, That is, the main function does not need the user to return any value . It should be noted that ,main There can be only one function in a program code . It's best to add... At the end of each main function code getchar();, In this way, the program will not flash after each code run , Especially when running .exe Document and release When you release a version, you need to pay more attention to , debugging debug Version will automatically reserve the console observation effect for the test function in the debugging stage, which can be ignored getchar() Use .
notes :debug To debug a program , That is, the program code that is still in the test and development stage , Also not yet released code phase .Release For the release version of the code , Compiled into this version of .exe Program files can be shared with others , And the actual size ratio debug Lower version .
③ User defined functions —— Personalized demand function defined according to actual function , Placed in the main function can realize various functions , But the return value of each function can only have one , The format is : return type + Function name + parameter list .
3. edit + compile + link + function
① edit —— Editing code is to describe the specific implementation of function functions , By defining variables line by line , The input character , Insert the function , By file, etc C The text entered by the grammar rules is finally edited to .c For the suffix C Source code file .
② compile : Compilation is edited by the compiler .c The source code file of the suffix is translated into an assembly language instruction expressed in .obj Target file for suffix , Usually a source code file corresponds to a target file ( An object file contains multiple assembly code files, so compilation can be divided into precompile , Compile and assemble ), In this process, the syntax of the source program is automatically checked and the error type and location are marked for users to modify .
③ link : The target file formed in the compilation stage .obj Link and summarize the assembly code files in , Finally, it is generated with .exe Executable program file with suffix .
example : Programming Hello World
The basic situation of program editing and compilation is clarified , You can start the simple writing of personal programs .
- Create new projects and new project files , Project selection C++ Empty item and need to make your own name ( No spaces and special characters , It's best to underline between English words _ Separate ) And choose the path .
- Create a new source file and select C++ type , Enter the code editing link , There are several aspects to pay attention to at this stage :
① If you use 2013 Version above Microsoft VS compiler , It's best to install the root directory of the compiler by default vs\Common7\IDE\VC\VCProjectitems Find below newc++file, This file is the format file of the new source file , That is, the default source code template generated every time a new project is created . Use notepad++ Or notepad ( You need to copy it to the desktop and then copy it back to overwrite it, so as to avoid insufficient permissions ) Open and add a sentence #define _CRT_SECURE_NO_WARNINGS 1, Then save . The purpose of this statement is to add preprocessing definitions to the compiler , For such as scanf and strcpy or getchar,gets And other older versions ( Input type )C When using library functions or macros, it may cause problems such as buffer overflow and memory out of bounds , Because such functions do not check boundaries when reading data , It's an unsafe function , Therefore, adding the predefined instruction is compatible with this kind of function .
② Edit code —— After importing standard I / O header file , Define the main function main, Insert in C Standard library functions printf, This function is a formatted output function , Its function declaration is built into the imported header file stdio.h in , The format is printf("< Formatted string >", < parameter list >), The string selected in double quotation marks and the formatted parameters assigned by the parameter list can be output to stdout, That is, print to the screen . Type in “Hello World” It should be noted that double quotation marks should be English characters , Chinese characters are not received and will report errors . Notice that the quotation mark also contains the escape character “\n”, Escape character in C The definition of language can show ASCII Characters that cannot be displayed in the code ,“\n” It's one of them , Its function is to move the cursor pointer to the first grid of the next line after outputting the string of characters , Enter immediately .
Code and result display
版权声明
本文为[VelvetShiki_ Not_ VS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231411217236.html
边栏推荐
- OpenSSH的升级、版本号的修改
- Branch statement of process control
- Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
- LLVM - 生成局部变量
- Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
- LLVM - 生成加法
- AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
- Basic regular expression
- 微信小程序轮播图swiper
- Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
猜你喜欢
如何5分钟上手使用OCR
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
KVM learning resources
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
Parameter stack pressing problem of C language in structure parameter transmission
flannel 原理 之 TUN模式
redis的五种数据类型
KVM学习资源
随机推荐
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
如何5分钟上手使用OCR
Qt界面优化:Qt去边框与窗体圆角化
Matrix exchange row and column
Parameter stack pressing problem of C language in structure parameter transmission
API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
流程控制之分支语句
网页自适应,等比缩放
kprobe 的 3 种使用
初识STL
SSH 通过跳板机连接远程主机
C语言知识点精细详解——初识C语言【1】
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
source insight via samba
c语言在结构体传参时参数压栈问题
Man man notes and @ reboot usage of crontab
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
Use cases of the arrays class
修改Firebase Emulators的默认侦听IP