当前位置:网站首页>C traps and defects Chapter 3 semantic "traps" 3.4 avoid "couple method"
C traps and defects Chapter 3 semantic "traps" 3.4 avoid "couple method"
2022-07-29 03:02:00 【weixin_ Guest time】
avoid “ Couple lifting method ”
“ Couple lifting method ”(synecdoche) It is a means of literary rhetoric , It's a little similar to expressing joy with a smile 、 Approval , Or metaphorically express the relationship between the referent and the referent . stay 《 Oxford English dictionary 》 in , Yes “ Couple lifting method ”(synecdoche) That's how it's explained :“ Replace the relatively narrow words with broader words , Or vice versa ; for example , The whole represents the part , Or part represents the whole , To represent biological species by biological classes , Or to represent biological classes with biological species , wait .”
C A common language “ defects ”: Confuse the pointer with the data pointed to by the pointer . In the case of strings . Programmers often make such mistakes .
for example :
char *p, *q;
p = "xyz";
The above assignment statement makes p The value of is a string "xyz", However, this is not the case , It is particularly important to remember this . actually ,p The value of is a point with 'x'、'y'、'z' and '\0' this 4 Pointer to the starting element of an array of characters . therefore , If we execute the following statement :
q = p;
p and q Now there are two pointers to the same address in memory . This assignment statement does not copy characters in memory at the same time .
Here's the thing to remember , The assignment pointer does not copy the data pointed to by the pointer at the same time .
therefore , When we execute the following statement :
q[1] = 'Y';
q The memory referred to now stores strings 'xYz'. because p and q It points to the same memory , therefore p Of course, what is stored in the memory pointed to is also a string 'xYz'.
Translation notes :ANSI C The standard stipulates that string literal Make changes .K&R C The explanation of this problem in is , The behavior of trying to modify a string constant is undefined . some C The compiler also allows q[1]='Y' This modification behavior , Such as LCC v3.6. however , This kind of writing is not worth advocating .
边栏推荐
- Verilog:阻塞赋值和非阻塞赋值
- Summary of common hooks
- 《QA离业务代码能有多近?》QA对业务代码进行可测性改造
- centos安装mysql8
- Confusion matrix learning notes
- 2.nodejs--路径(_dirname,_filname)、url网址、querystring模块、mime模块、各种路径(相对路径)、网页的加载(面试题*)
- Analysis of OWT server source code (III) -- video module analysis of mixer in
- Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers
- Flink kernel source code (VII) Flink SQL submission process
- My approval function of conference OA project
猜你喜欢

百度副总裁李硕:数字技术加持下中国劳动力成本上升是好事

Redis configuration cache expiration listening event trigger

sqlilabs less-32~less-33

解析机器人与人类情感共鸣的主观意识
![[open the door to the new world] see how the old bird of testing plays API testing between applause](/img/79/1bc836cefef24d23e09d9865ff1fba.png)
[open the door to the new world] see how the old bird of testing plays API testing between applause

爆肝整理JVM十大模块知识点总结,不信你还不懂

centos安装mysql8

【C】数组

盘点国内外项目协同管理软件:SaaS和定制化成趋势

vasp计算任务报错:M_divide:can not subdivide 8 nodes by 6
随机推荐
向DataFrame中的特定位置添加一行
《QA离业务代码能有多近?》QA对业务代码进行可测性改造
Analysis of Project-based Learning Creativity in steam Education
C和指针 第3章 语义“陷阱” 3.5 空指针并非字符串
Day 8 notes
seed 随机种子
C#从网址异步获得json格式的数据
[Luogu p8352] independent set of small n (DP set DP) (property)
Pytest environment deployment + use case execution management + use case parameterization
SQL查询数据之多表(关联)查询
Object转String的几种方法
Navicat new database
Linux下安装MySQL8.0的详细步骤
会议OA项目之我的审批功能
Idea replaces the contents of all files
mysql大表联合查询优化,大事务优化,规避事务超时,锁等待超时与锁表
OSPF experiment
Multi table (Association) query of SQL query data
Confusion matrix learning notes
Interpreting AI robots' pet raising and leading fashion trends