当前位置:网站首页>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)[];
边栏推荐
猜你喜欢

空间数据库开源路,超图+openGauss风起禹贡

Jmeter combat | Repeated and concurrently grabbing red envelopes with the same user

包含吲哚菁绿的多聚体白蛋白纳米球/载马钱子碱纳米粒的牛血清白蛋白微球的制备

左旋氧氟沙星/载纳米雄黄磁性/As2O3磁性Fe3O4/三氧化二砷白蛋白纳米球

Transplant MQTT source code to STM32F407 development board

方舟开服需要知道的那些事

PyQt5 + MySQL5.8 【学生信息管理系统】【增删改查】

C专家编程 第1章 C:穿越时空的迷雾 1.4 K&R C

LeetCode·每日一题·1374.生成每种字符都是奇数个的字符串·模拟

C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.4 K&R C
随机推荐
C专家编程 第1章 C:穿越时空的迷雾 1.3 标准I/O库和C预处理器
C Expert Programming Preface
如何封装 cookie/localStorage/sessionStorage hook?
通过这两个 hook 回顾 Set/Map 基础知识
分类接口,淘宝分类详情 API
C陷阱与缺陷 第7章 可移植性缺陷 7.10 首先释放,然后重新分配
An online JVM FullGC made it impossible to sleep all night and completely crashed~
附录A printf、varargs与stdarg A.3 stdarg.h ANSI版的varargs.h
方舟生存进化是什么游戏?好不好玩
【Jmeter常用断言组件】
PX4模块设计之十五:PX4 Log设计
【力扣】字符串相乘
深拷贝浅拷贝
虚拟内存与物理内存之间的关系
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.1 The Prehistoric Phase of the C Language
Review Set/Map basics with these two hooks
JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)
测试的意义并不是能找到全部的缺陷
网红驼背矫正产品真的管用吗?如何预防驼背?医生说要这样做
HCIP---企业网的架构