当前位置:网站首页>C expert programming
C expert programming
2022-08-01 21:21:00 【weixin_Guest time】
1. Demonstrate the coding skills used by excellent C programmers;
2. Detailed explanation and in-depth analysis of C's history, language features, declarations, arrays, pointers, links, runtime, memory, and how to further study C++.
3. Help C programmers with certain experience become experts in C programming; help programmers with deep knowledge of C language to understand and learn C++ from the height of C.
Programming philosophy: Anyone can enjoy programming.
Programming should be a wonderful, dynamic, and challenging activity, and a book about programming should spark a spark of passion from time to time.
Applies to ANSI standard C language on PC and UNIX systems. It describes the features in C language related to the complex hardware structure of UNIX platform (such as virtual memory, etc.)A comprehensive introduction to the impact of the C language.
Many topics that confuse C programmers:
What does*typedef struct bar{ int bar; }bar really mean?
Analysis:
The first bar is the structure tag, the second bar is the member variable name in the structure, and the third bar is the structure type.
#include
typedef struct bar {
int bar;
int z;
}bar;
/*The first bar is a structure tag name
*The second bar is a variable name of bar of type int in the structure
*The third bar is a structure type name
*struct bar struct type
*struct bar bar The first bar is a structure label, the second bar is an object name
*bar.bar The first bar is an object name, and the second bar objectmember variable of name
*/
int main() {
//error
/*typedef struct bar bac; //not allowed!
bac.bar = 5;*/
bar bar;
bar.bar = 3;
struct bar baz;
baz.bar = 4;
printf("sizeof(bar) = %d,sizeof(struct bar) = %d\nsizeof(bar.bar) =%d,sizeof(baz.bar) = %d\n",
sizeof(bar), sizeof(struct bar), sizeof(bar.bar), sizeof(baz.bar));
printf("bar.bar = %d, baz.bar = %d\n", bar.bar, baz.bar);
Return 0;
}
/* output:
*/
*How do I pass some multidimensional arrays of different sizes into the same function?
Analysis:
Multidimensional arrays of different sizes can be passed into the same function by flattening the array into a one-dimensional array.
*Why extern char *p; cannot match the char p[100]; of another file?
Analysis:
Why do people think that pointers and arrays should always be interchangeable?The answer is that a reference to an array can always be written as a reference to a pointer, and there does exist a context where pointers and arrays are defined exactly the same.Unfortunately, this is only a very common use of arrays, and this is not the case in all cases.When you extract the contents of this declaration in the form p[i], you actually get a single character.But according to the pointer method, the compiler treats it as a pointer, and interpreting ASCII characters as addresses is obviously wrong.
*What is a bus error? What is a segmentation violation?
Analysis:
A bus error is due to an unaligned memory access request, and the blocked component is the address bus.Alignment means that data items can only be stored in memory locations whose addresses are an integer multiple of the size of the data item.In fact, bus errors are almost always caused by misaligned reads or writes.Segmentation violations are generally caused by exceptions in the memory management unit (the hardware responsible for supporting virtual memory), which are usually caused by de-initializing a pointer to an uninitialized or illegal value.
What is the difference between *char *foo[] and char (*foo)[]?
Analysis:
//foo is a pointer, elements in array is a pointer points to the char
char *foo[];
//foo is a pointer, pointer points to a array of char
char(*foo)[];
边栏推荐
- Get started with Grafana in 15 minutes
- 列表页常见的 hook 封装
- SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
- 关于npm的那些事儿
- 【中文树库标记---CTB】
- LeetCode
- C pitfalls and pitfalls Chapter 8 Suggestions and answers 8.2 Answers
- C Pitfalls and pitfalls Appendix B Interview with Koenig and Moo
- C陷阱与缺陷 附录B Koenig和Moo夫妇访谈
- 关于Request复用的那点破事儿。研究明白了,给你汇报一下。
猜你喜欢
随机推荐
C陷阱与缺陷 第8章 建议与答案 8.1 建议
C专家编程 第1章 C:穿越时空的迷雾 1.2 C语言的早期体验
”sed“ shell脚本三剑客
C Pitfalls and Defects Chapter 7 Portability Defects 7.7 Truncation During Division
测试开发人均年薪30w+?软件测试工程师如何进阶拿到高薪?
树莓派的信息显示小屏幕,显示时间、IP地址、CPU信息、内存信息(c语言),四线的i2c通信,0.96寸oled屏幕
C陷阱与缺陷 第7章 可移植性缺陷 7.11 可移植性问题的一个例子
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.1 The Prehistoric Phase of the C Language
C Expert Programming Preface
C陷阱与缺陷 第7章 可移植性缺陷 7.6 内存位置0
R语言 pca主成分分析的主要方法
关于npm的那些事儿
网红驼背矫正产品真的管用吗?如何预防驼背?医生说要这样做
牛血清白蛋白刺槐豆胶壳聚糖缓释纳米微球/多西紫杉醇的纳米微球DTX-DHA-BSA-NPs
Pytorch学习记录(八):生成对抗网络GAN
图片识别商品接口 API:天猫淘宝
Jmeter实战 | 同用户重复并发多次抢红包
C专家编程 前言
C陷阱与缺陷 第7章 可移植性缺陷 7.8 随机数的大小
C Pitfalls and Defects Chapter 5 Library Functions 5.5 Library Function Signal