随笔分类 -  c语言学习

摘要:#define 定义宏 宏(Macro)是预处理命令的一种,它允许用一个标识符来表示一个字符串 1.有关定义宏的代码末尾不需要添加";"(分号) 2.定义宏define在计算的式子中相当于替代,类似于数学中的需要带入数值的x #include <stdio.h> #define ADD(x,y) x 阅读全文
posted @ 2022-01-14 17:25 programmer-lite 阅读(112) 评论(0) 推荐(0) 编辑
摘要:extern关键字的使用 作用:声明外部符号(使用其他文件的全局变量) 例子: 源文件: test.c #include <stdio.h> extern int year;//使用extern关键字从add.c源文件中声明外部符号的全局变量 int main(){ printf("%d", yea 阅读全文
posted @ 2022-01-14 17:24 programmer-lite 阅读(34) 评论(0) 推荐(0) 编辑
摘要:static关键字的使用 static:静态 未使用static 在下列代码中变量a是有生命周期的,调用完后就会被销毁 所以for循环每次调用test函数打印的结果都是2 #include <stdio.h> void test() { int a = 1; a++; printf("%d", a) 阅读全文
posted @ 2022-01-14 17:24 programmer-lite 阅读(33) 评论(0) 推荐(0) 编辑
摘要:c-逗号运算符 使用逗号运算符是为了把几个表达式放在一起。 整个逗号表达式的值为系列中最后一个表达式的值。 值4=(值1,值2,值3);//值4=值3,运算顺序从左到右 #include <stdio.h> int main(){ int a = 1; int b = 2; int c = 3; i 阅读全文
posted @ 2022-01-10 14:49 programmer-lite 阅读(65) 评论(0) 推荐(0) 编辑
摘要:1.移位操作符 <<左移: a=b<<n a=b乘以2的n次方 >>右移: a=b>>n a=b除以2的n次方 简单理解: #include <stdio.h> int main(){ int a = 200; int b = a << 3;//a乘以2的3次方 int c = a >> 2;//a 阅读全文
posted @ 2022-01-10 14:48 programmer-lite 阅读(156) 评论(0) 推荐(0) 编辑
摘要:c-->字符串 \0(数字)字符 字符串在结尾的位置隐藏 的一个\0的字符 \0是字符串的结束标志 #include <stdio.h> int main(){ char arr1[] = "abc"; char arr2[] = { 'a', 'b', 'c' }; char arr3[] = { 阅读全文
posted @ 2022-01-04 14:05 programmer-lite 阅读(117) 评论(0) 推荐(0) 编辑
摘要:c-->常量 1.字面常量 #include <stdio.h> int main(){ 123;//字面常量 "string";//字面常量 printf("hello word!"); } 2.const 修饰符修饰的常变量 被修饰的变量叫常变量仍然是变量,具有常属性(不可改变的属性) #inc 阅读全文
posted @ 2022-01-04 10:44 programmer-lite 阅读(55) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示