当前位置:网站首页>Standard C language learning summary 5
Standard C language learning summary 5
2022-07-28 07:07:00 【c7473168】
One , Function arguments
1, The shape parameter , The variables defined in the function only belong to the function it is in ,
This function cannot be used anymore
2, Ordinary real participants transfer data between formal parameters by assignment ( One way value passing )
3,return It's actually storing data in a public area ( Functions can access ), If you don't write return sentence ,
Then it will read that the area originally refers to , Get a piece of junk data
4, Array as a function parameter is , The length in brackets will be lost
You need to add an extra variable to pass the length of the array
5, When an array is passed as a function parameter , Pass is the first address of the array , be called " Address delivery " Functions and callers of functions can share the same array
1, A function is best to solve a problem , Reduce the error rate , Readability improvement
2, Try to reduce the number of dependency layers between functions ( Reduce coupling )
3, The data is provided by the caller , The result is returned to the caller ( Improve versatility )
4, Consider the illegal parameters of the function , You can tell the caller that the parameter is incorrect by returning a value ,
You can also write the situation in the form of notes ( Improve the robustness of functions )
Process image
Program : Executable files stored on disk ( Binary , Script files )
process : Programs running in the system
Process image : It refers to the process memory distribution
text Code segment Store binary instructions , const data , Permission is read-only ,
Forced modification will produce segment errors
data Data segment Initialized global variables , Initialized static local variables
bss Static data segment Uninitialized global variables , This section of memory will be automatically cleaned up as 0
Uninitialized static local variables ,
stack Stack local variable , Block variable Managed by the operating system ,
It will automatically apply for , Free memory Small memory
heap Pile up Manually managed by the programmer , advantage : Large enough
Local and global variables :
Global variables : Variables defined outside the function
Storage location :data( initialization ) perhaps bss( uninitialized )
Life cycle : From the beginning of the program to the end of the program
Scope of action : Anywhere in the program
local variable : Variables defined in functions
Storage location :stack Stack memory
Life cycle : From function call definition to function end
Scope of action : Can only be used within a function
Block variable : Variables defined in a statement block if\for\while
Storage location :stack Stack memory
Life cycle : From function call definition to function end
Scope of action : Can only be used within a statement block
Be careful : Local variables can have the same name as global variables , Local variables in functions will mask global variables with the same name ,
Block variables will mask the global with the same name in the statement block , local variable , Therefore, it is recommended that global variables be capitalized
3、 ... and , Type qualifier
auto Used to define automatic memory allocation , Free variables in memory ( local variable ), Not adding means adding
Be careful : Global variables cannot use auto Embellished
stay C11 For automatic identification of types
extern
Declare variables : extern Type name Variable name ;
Tell the compiler that this variable has been defined elsewhere , Please feel free to use
But you can only let the compilation pass temporarily , But if you can't find the definition that can't be changed when linking , Still report a mistake
You can no longer assign values when declaring variables
In multi file programming , hypothesis a.c Define global variables in N, Want to be in b.c Use in N,
You need to declare this variable before using
static"
Change storage location :
Change the storage location of local variables , from stack Change it to data perhaps bss( Depends on whether to initialize )
The local variables modified by it are called static local variables
Extending the life cycle :
Prolongs the life cycle of local variables , Until the end of the process
Limit the scope of action :
Limit the scope of global variables , Only in this document
Can prevent global variables , Function naming conflict , It can also prevent being used by other files "
const
" Protect " The value of a variable cannot be changed explicitly
But you can modify the value by accessing memory
But if you decorate an initialized global variable , Initialized static local variables
Then the variable will change from data Change it to text, Turned into " Constant " Cannot force modification ,
volatile
If the value of the variable is not displayed and modified , Then when using this variable, it will not be read from memory ,
Instead, continue to use the last read result , This process is called value optimization , General variables will be .
Variable is volatile After modification , The compiler does not optimize the value of this variable , It will be re read from memory every time
General hardware programming , Multithreaded programming will use
volatile int num = 10;
if(num == num) // It may be false
storage medium : Hard disk -> Memory -> Advanced caching -> register
register
Apply to change the storage medium of variables from memory to registers , Due to the limited number of registers, the application may not be successful
Be careful : Register variables cannot take addresses
typedef
Type redefinition ,
When defining variables , If you add typeodef, Then the variable name becomes the new type name of this type
typedef int num;
int a;
num b;
Be careful :typedef It's not a replacement relationship
边栏推荐
- 爬虫学习总结
- [learning notes] thread creation
- How to describe a bug and the definition and life cycle of bug level
- shell---循环语句练习
- Custom components -- slots
- Erudite Valley Learning Records] Super summary, attentive sharing | common APIs
- Method of designing test cases
- Result number of filled briquettes
- 登录进oracle10g的oem,想管理监听程序却总是弹出帐号密码输入页面
- 多进程(多核运算)Multiprocessing
猜你喜欢

Repair the faulty sector

Bond mode configuration

easypoi导出表格带echars图表

NAT-网络地址转换

Custom component -- data listener

MOOC翁恺C语言第七周:数组运算:1.数组运算2.搜索3.排序初步

shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置

Blue Bridge Cup square filling number

Servlet

Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
随机推荐
MySQL排除节假日,计算日期差
Shell script - "three swordsmen" awk command
DOM - Events
Operation document tree
Method of designing test cases
三层交换和VRRP
DOM -- event chain, event bubble and capture, event proxy
DOM operation cases
shell---条件语句练习
Neo4j running error occurred during initialization of VM incompatible minimum and maximum heap sizes spec
Reptile learning summary
MOOC翁恺 C语言 第三周:判断与循环:1.判断
Applets: lifecycle
Event_ Loop event loop mechanism
Esxi community network card driver
Three cache technologies -- localstorage, sessionstorage, cookies
Archery database audit platform deployment
DOM -- page rendering, style attribute operation, preloading and lazy loading, anti shake and throttling
DNS domain name resolution
PXE unattended installation management