有意思的
Spark!
路人
展开
-
C移位问题
int a = 2;for(int i = 0; i < 100; i++){ a *= 2;}a最终是0可以看这段代码#include "stdio.h"int main(){ int a = 1 << 31; printf("a is:%d\na << 1 is %d\n", a, a << 1); return 0;}C对越界的处理就是直接舍弃同时要注意,有符号数的最高位为符号位...原创 2021-08-26 09:19:39 · 198 阅读 · 0 评论 -
有意思的题:(++a * a++)、(b++ * ++b)、(c++ * c++)、(++d * ++d)
#include <stdio.h>int main(){ int a = 3, b = 3, c = 3, d = 3; int a1, b1, c1 ,d1; a1 = (++a * a++); b1 = (b++ * ++b); c1 = (c++ * c++); d1 = (++d * ++d); printf("%d %d %d %d\n",a1, b1, c1, d1); return 0;}运行结果为20 15 12 251、++a先自加后使用,原创 2021-05-13 00:14:11 · 1305 阅读 · 2 评论 -
如何调用其他文件的static函数
方法:include 目标static函数的.c文件通过函数包住static函数,另一文件调这个函数通过static的地址调用优点可能是为了兼容性这么玩,缺点如果一个大工程这样写,文件会很多很乱不容易规划第一种//a.c#include <stdio.h>//#include "b.h"#include "b.c"int main(void){ test_func(); return 0;}// b.c#include <stdio.h原创 2021-04-16 19:10:37 · 6013 阅读 · 0 评论 -
下面的代码片段的输出是什么,为什么? char *ptr; if ((ptr = (char *)malloc(0)) == NULL) puts(“Gota null pointer“);
下面的代码片段的输出是什么,为什么?char *ptr;if ((ptr = (char *)malloc(0)) == NULL)puts(“Gota null pointer”);elseputs(“Gota valid pointer”);这个你可以先大胆猜测下,然后再用你的编译器尝试着编译下~~程序如下#include <stdio.h>#include <malloc.h>int main(){ char *ptr;原创 2021-02-27 14:37:28 · 2317 阅读 · 2 评论