当前位置:网站首页>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)[];
边栏推荐
猜你喜欢
随机推荐
那些关于DOM的常见Hook封装(一)
C Pitfalls and Defects Chapter 7 Portability Defects 7.8 Size of Random Numbers
C语言_联合体共用体引入
ISC2022 HackingClub白帽峰会倒计时1天!最全议程正式公布!元宇宙集结,精彩绝伦!
C Pitfalls and Defects Chapter 7 Portability Defects 7.6 Memory Location 0
在Cesium中实现与CAD的DWG图叠加显示分析
使用员工管理软件,解锁人力生产力新水平,提高人力资源团队灵活性
2022牛客多校联赛第五场 题解
Taobao's API to get the list of shipping addresses
那些关于DOM的常见Hook封装(二)
C Expert Programming Preface
Pytorch学习记录(八):生成对抗网络GAN
软考 ----- UML设计与分析(上)
响应式织梦模板美容整形类网站
方舟开服需要知道的那些事
Jmeter combat | Repeated and concurrently grabbing red envelopes with the same user
Jmeter实战 | 同用户重复并发多次抢红包
C专家编程 前言
数据库练习
多商户商城系统功能拆解19讲-平台端发票管理