摘要: 程序一:struct student{char *name;int score;} stu,*pstu;int main(){strcpy(stu.name,"Jimy");stu.score = 99;return 0;}问程序有何错误?答:错误在于struct中只是定义了指针name,并未分配空 阅读全文
posted @ 2020-01-29 10:06 wuqi1003 阅读(132) 评论(0) 推荐(0) 编辑
摘要: char *p1="abcd";char *p2=(char*)malloc(sizeof(char) * strlen(p1));strcpy(p2,p1);解析:p2指向空间太小了,p1指向空间实际除了abcd四个char外,还有'\0'一个char,所以应该是strlen(p)+1。 阅读全文
posted @ 2020-01-29 10:05 wuqi1003 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 对数组初始化也可用memset:memset(a,0,sizeof(a)); 阅读全文
posted @ 2020-01-29 10:04 wuqi1003 阅读(520) 评论(0) 推荐(0) 编辑
摘要: void fun(int i){if(i>0) fun(i/2);printf("%d\n",i);}void main(){fun(10);}问:程序输出结果?答案: 012510 阅读全文
posted @ 2020-01-29 09:57 wuqi1003 阅读(176) 评论(0) 推荐(0) 编辑
摘要: int my_strlen(char *strDest){assert(strDest != NULL); //注释①if('\0' == *strDest)return 0;else //注释②return (1+my_strlen(++strDest));}注释①:assert是个宏,不是库函数 阅读全文
posted @ 2020-01-29 09:51 wuqi1003 阅读(255) 评论(0) 推荐(0) 编辑
摘要: #ifndef _FILENAME_H_#define _FILENAME_H_头文件内容#endif 阅读全文
posted @ 2020-01-29 09:49 wuqi1003 阅读(205) 评论(0) 推荐(0) 编辑
摘要: static int j;int k=0;void fun1(void){static int i=0; //注释①i++;}void fun2(void){j=0; //注释②j++;}int main(){for(k=0; k<10; k++){fun1();fun2();}return 0;} 阅读全文
posted @ 2020-01-29 09:44 wuqi1003 阅读(809) 评论(0) 推荐(0) 编辑
摘要: 元素单目乘除余, 加减移位大小等, 位与异或逻与或, 条件赋值组合逗。 元素: () [] -> . 单目: ! ~ ++ -- (type)类型转换 * & sizeof 乘除余:* / % 加减: + - 移位: << >> 大小: < <= > >= 等: == != 位与: & 位异或:^ 阅读全文
posted @ 2020-01-29 09:43 wuqi1003 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 程序员面试宝典中的叙述: 1,const 进行类型检查 2. const支持一些编译器的断点调试 (以上两点#define都不具有) 网友补充 编译器检查类型,避免宏替换错误,如 #define t 1+1 t = t * 2; 你的答案应该是4, 但程序会输出3, 因为 1+1*2 = 3, 但是 阅读全文
posted @ 2020-01-29 09:41 wuqi1003 阅读(439) 评论(0) 推荐(0) 编辑
摘要: extern "C"的用法解析 2012-03-20 23:29 by Rollen Holt, 88007 阅读, 16 评论, 收藏, 编辑 1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一 阅读全文
posted @ 2020-01-29 09:40 wuqi1003 阅读(435) 评论(0) 推荐(0) 编辑