2525
2626需要注意的问题:
2727
28- 1 . 语法问题:由于是纯文本替换,C预处理器不对宏体做任何语法检查,像缺个括号、少个分号神马的预处理器是不管的 。
28+ 1 . 语法问题:由于是纯文本替换,C预处理器不对宏体做任何语法检查,像缺个括号、少个分号之类的错误预处理器是不管的 。
29292 . 算符优先级问题:不仅宏体是纯文本替换,** 宏参数也是纯文本替换** 。有以下一段简单的宏,实现乘法:
3030
3131 #define MULTIPLY(x, y) x * y
4444
4545[[ 宏定义中存在依赖时展开问题] ( http://www.nowcoder.com/questionTerminal/c33295e54974412095ebadab0f5bb820 ) ]
4646
47- 参考
48- [ C语言宏的特殊用法和几个坑] ( http://hbprotoss.github.io/posts/cyu-yan-hong-de-te-shu-yong-fa-he-ji-ge-keng.html )
49- 《Effective C++》 条款02:尽量以const, enum, inline 代替 #define,预处理器不够安全。
50-
5147## C 风格字符串的函数
5248
5349C风格字符串不是一种类型,而是为了表达和使用字符串而形成的一种约定俗成的写法。按此习惯写的字符串存放在` 字符数组中并以空字符('\0')结束 ` ,一般利用指针来操作这些字符串。
5450
5551C 语言标准库提供了一组函数用于操作 C 风格字符串,定义在 cstring 头文件中。
5652
57- 1 . strcat(p1, p2):将p2附加到p1之后,且会覆盖null字符,最后返回p1;[[ 对应题目 ] ( http ://www.nowcoder.com/test/question/done?tid=2494453&qid=25523#summary ) ]
58- 2 . strlen(p):返回p的长度,** 遇到空字符'\0'结束** ,空字符不计算在内; [ [ 对应题目 ] ( http://www.nowcoder.com/questionTerminal/81cc723e49fc402ca7fa62a97a121251 ) ]
53+ 1 . strcat(p1, p2):将p2附加到p1之后,且会覆盖null字符,最后返回p1;[[ 题目 ] ( https ://www.nowcoder.com/questionTerminal/3004651f5407480b8ae8e9dbdead9073 ) ]
54+ 2 . strlen(p):返回p的长度,** 遇到空字符'\0'结束** ,空字符不计算在内;sizeof返回数组所占的字节数。[ [ 题目 ] ( http://www.nowcoder.com/questionTerminal/81cc723e49fc402ca7fa62a97a121251 ) ]
59553 . strcmp(p1, p2):比较 p1 和 p2 的相等性,如果 p1 == p2,返回0,p1 > p2返回一个正值;p1 < p2 返回一个负值。
60564 . strcpy(p1, p2):将p2拷贝给p1,返回p1。
6157
62- ([ c_string_func.cpp] ( C++_Code /c_string_func.cpp) )
58+ ([ c_string_func.cpp] ( ../Coding /c_string_func.cpp) )
6359
6460[[ 字符串常量赋值] ( http://www.nowcoder.com/questionTerminal/462f7c3746814b1cadde05a1084f8740 ) ]
6561[[ strcpy 拷贝] ( http://www.nowcoder.com/questionTerminal/74d917fe09a94a2fb03b5371a2417372 ) ]
6662[[ 字符串常量和字符数组] ( http://www.nowcoder.com/questionTerminal/0db8ed5d69464f0bbb98d5eba3c08b9a ) ]
6763
68- 参考:
69- 《C++ Primer》 Page109
70- [ What is the difference between char s[ ] and char * s in C?] ( http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c )
71- [ Why do I get a segmentation fault when writing to a string initialized with “char * s” but not “char s[ ] ”?] ( http://stackoverflow.com/questions/164194/why-do-i-get-a-segmentation-fault-when-writing-to-a-string-initialized-with-cha )
72-
7364## printf 格式化字符串
7465
7566printf 函数是一个标准库函数,它的函数原型在头文件“stdio.h”中。printf函数调用的一般形式为:
@@ -100,16 +91,9 @@ printf 函数是一个标准库函数,它的函数原型在头文件“stdio.h
10091
10192[[ 八进制输出] ( http://www.nowcoder.com/questionTerminal/25bce0284ec040fabdf6629dbd0c5dc9 ) ]
10293
103- 参考
104- [ cplusplus: printf] ( http://www.cplusplus.com/reference/cstdio/printf/?kw=printf )
105- [ C语言格式输出函数printf()详解] ( http://c.biancheng.net/cpp/html/33.html )
106- [ Where is %p useful with printf?] ( http://stackoverflow.com/questions/2369541/where-is-p-useful-with-printf )
107-
10894## 整型溢出
10995
110- 对于整型溢出,分为无符号整型溢出和有符号整型溢出。
111-
112- 对于unsigned整型溢出,C的规范是有定义的——` 溢出后的数会以2^(8*sizeof(type))作模运算 ` ,也就是说,如果一个unsigned char(1字符,8bits)溢出了,会把溢出的值与256求模。
96+ 对于整型溢出,分为** 无符号整型溢出和有符号整型溢出** 。对于unsigned整型溢出,C的规范是有定义的——` 溢出后的数会以2^(8*sizeof(type))作模运算 ` ,也就是说,如果一个unsigned char(1字符,8bits)溢出了,会把溢出的值与256求模。
11397
11498当一个算术表达式中既有无符号数又有有符号数时,就会将有符号值转换为无符号值。
11599
@@ -127,10 +111,6 @@ printf 函数是一个标准库函数,它的函数原型在头文件“stdio.h
127111
128112[[ For 循环次数] ( http://www.nowcoder.com/questionTerminal/7183f3428a444efe8a3f91247ddf6b7a ) ]
129113
130- 参考
131- [ C语言的整型溢出问题] ( http://coolshell.cn/articles/11466.html )
132- [ 从Swap函数谈加法溢出问题] ( http://blog.csdn.net/dataspark/article/details/9703967 )
133-
134114## 位段
135115
136116有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位。例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可。为了节省存储空间,并使处理简便,C语言又提供了一种数据结构,称为“位域”或“位段”。
@@ -156,21 +136,30 @@ printf 函数是一个标准库函数,它的函数原型在头文件“stdio.h
156136
157137[[ 位域结构体的大小] ( http://www.nowcoder.com/questionTerminal/07adfd96a2364433a6538c9bb0fcda16 ) ]
158138
159- 参考
160- [ 浅谈C语言中的位段] ( http://www.cnblogs.com/dolphin0520/archive/2011/10/14/2212590.html )
161-
162139## 柔性数组
163140
164141
142+
165143[[ 结构体柔性数组作用] ( http://www.nowcoder.com/questionTerminal/be5269b8c2d340c3add69510d0089747 ) ]
166144
167- 参考
168- [ C语言结构体里的成员数组和指针] ( http://coolshell.cn/articles/11377.html )
169- [ Arrays of Length Zero] ( https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html )
145+ # 更多阅读
170146
147+ 《C++ Primer》 Page109
148+ 《Effective C++》 条款02:尽量以const, enum, inline 代替 #define,预处理器不够安全。
171149
172- # 更多阅读
150+ [ What is the difference between char s[ ] and char * s in C?] ( http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c )
151+ [ Why do I get a segmentation fault when writing to a string initialized with “char * s” but not “char s[ ] ”?] ( http://stackoverflow.com/questions/164194/why-do-i-get-a-segmentation-fault-when-writing-to-a-string-initialized-with-cha )
152+ [ Where is %p useful with printf?] ( http://stackoverflow.com/questions/2369541/where-is-p-useful-with-printf )
153+ [ cplusplus: printf] ( http://www.cplusplus.com/reference/cstdio/printf/?kw=printf )
154+ [ Arrays of Length Zero] ( https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html )
173155
156+ [ C语言宏的特殊用法和几个坑] ( http://hbprotoss.github.io/posts/cyu-yan-hong-de-te-shu-yong-fa-he-ji-ge-keng.html )
174157[ C语言的谜题] ( http://coolshell.cn/articles/945.html )
175158[ 语言的歧义] ( http://coolshell.cn/articles/830.html )
159+ [ C语言格式输出函数printf()详解] ( http://c.biancheng.net/cpp/html/33.html )
160+ [ C语言的整型溢出问题] ( http://coolshell.cn/articles/11466.html )
161+ [ 从Swap函数谈加法溢出问题] ( http://blog.csdn.net/dataspark/article/details/9703967 )
162+ [ 浅谈C语言中的位段] ( http://www.cnblogs.com/dolphin0520/archive/2011/10/14/2212590.html )
163+ [ C语言结构体里的成员数组和指针] ( http://coolshell.cn/articles/11377.html )
164+
176165
0 commit comments