当前位置:网站首页>C language review 12
C language review 12
2022-06-09 07:54:00 【Sakuragi】
C Language Check 12
C Language learning , Here is a video of Weng Kai from Zhejiang University , Muke website :https://www.icourse163.org/learn/ZJU-9001?tid=9001#/learn/content. The author's review notes are also mainly based on the video . The main contents of this paper are as follows
- Programming and design C Language
- Calculation
- Judge
- loop
- Cycle control
- data type
- function
- Array
- The pointer
- character string
- Structure type
- Programming
Global variables ; Compile preprocessing and macros ; Large program structure ; operate a computer 12; - file
- Linked list
refer
1.
12.1 Global variables
One 、 Lifetime and scope
A global variable is a variable defined outside a function ( Include main function ), Generally, it has global lifetime and scope , They can be used inside any function .
Two 、 Global variable initialization
Uninitialized local variables get an odd value , But if the global variable is not initialized, you will get 0 value , The pointer will get NULL value . Global variables can only be initialized with values known at compile time ( I can't use scanf), They are initialized in main Function before .
3、 ... and 、 Static local variables
Add modifier static Get the static local variables . When the function leaves , Static local variables continue to exist and keep their values . The initialization of static local variables will only be done when entering the function for the first time , In the future, each time you enter the function, you will keep the value of the last time you left .
Static local variables are actually special global variables , Has a global lifetime and a local scope within a function .
Four 、 Use less global variables and static local variables
Global variables and static local variables make threads unsafe .
12.2 Compile preprocessing and macros
One 、 Compile preprocessing instructions and macros
In the first picture we talked about , from .c After the file is pretreated, it becomes .i file , among # The beginning is the compilation preprocessing instruction , and #define Used to define a macro .
#define No C The sentence of , His use is as follows :define < name > < value >
12.3 Large program structure
One 、 Projects and compilation units
When our program is too large , There will be more than one .c file , And one .c The document is actually a Compilation unit , The compiler can only process one compilation unit at a time .
In a project project There will be multiple compilation units in the .c file , Compiler or IDE All source code files need to be compiled and linked .
yes , we have IDE Have separate compile and structure Two buttons , The former is compilation , The latter is to link the whole project .
Two 、 The header file
The function prototype Will be put into a header file (.h file ), You need to call this function in the source code file (.c file ) in #include This header file .
#include Is a compilation preprocessing instruction , Like macros , Before compiling, you need to deal with .
#include Yes #include <> and #include "" Two forms .
among #include "" The compiler will be asked to start in the current directory (.c File directory ) Look for this file , without , Go to the directory specified by the compiler ;#include <> The compiler will be asked to look only in the specified directory ; Be careful , environment variable And compiler command-line arguments can specify the directory to look for header files .mac The loading order of environment variables for is :
a. /etc/profile # System level
b. /etc/paths # System level
c. ~/.bash_profile # User level , Often find a
d. ~/.bash_login
e. ~/.profile
f. ~/.bashrc
#include It's not used to import and store , He just wanted the compiler to know printf Prototypes of functions , Ensure that the parameter values given during the call are of the correct type .
Generally any .c Each file has its corresponding file with the same name .h file , Put all function prototypes and global variable declarations in it .
Let's enjoy the source code of red alert :https://github.com/electronicarts/CnC_Remastered_Collection/tree/master/REDALERT
边栏推荐
- A group of interesting pictures to explain the status code
- PHP date format conversion simplified month day without 0, for example: 22.2.9
- Epoll series system call
- 实时监控,智能预警,疾控中心的战疫“速度”
- FTP service
- redis核心知识点总结(超详细)
- R language uses dlnorm function to generate lognormal distribution density data and plot function to visualize lognormal distribution density data
- 蓝桥杯电子类单片机第十一届决赛试题
- The latest Shanxi construction safety officer simulation question bank and answers in 2022
- Use of qflags flag class
猜你喜欢

Personal feeling: Hello, teacher. My name is he

Question bank and answers of 2022 special operation certificate for installation and repair of refrigeration and air conditioning equipment

At time_ What happens to TCP connections in wait status after SYN is received?

Advanced SQL query

PostgreSQL database replication - background first-class citizen process walreceiver extracts information

Fabric.js 激活输入框

PostgreSQL database replication - background first-class citizen process walreceiver ready_ to_ display

Solution to display < unknown > when Charles grabs packets in win system

Apache Web page and security optimization

C语言复习7
随机推荐
Fabric. JS activation input box
Robot_ Framework: Variables
PHP date format conversion simplified month day without 0, for example: 22.2.9
caffe安装步骤
YOLOv5添加注意力机制的具体步骤
【学校实验+蓝桥杯题目】接水问题:学校里有一个水房,水房里一共装有m个龙头可供同学们打开水,每个龙头每秒钟的供水量相等,均为1。现在有n名同学准备接水,他们的初始接水顺序已经确定......
Real time monitoring, intelligent early warning, CDC's "speed" of war and epidemic
redis核心知識點總結(超詳細)
Understand the whole test process with one diagram
CV学习笔记-CNN-VGG
MySQL: connection query
error converting YAML to JSON: yaml: line 10: found character that cannot start any token
Homebrew installing MySQL
2022 Chinese cook (elementary) examination question bank and online simulation examination
homebrew安装mysql
[cloud resident co creation] data center pue optimization model generation service: a money saving strategy for data centers under the AI wave, just use these tips
pushmall推贴共享电商2022年5月份计划更新完成
2022 national latest Fire Facility operator (Intermediate Fire Facility operator) test Simulated question base and Answers
「冲刺大厂基础1」
2022 hydrogenation process question bank and simulation test