摘要: int a[4]={1,2,3,4};int *p1=(int*)(&a+1);int *p2=(int*)((int)a+1);printf("%x,%x",p1[-1],*p2);解析:(1)数组索引可以是负数,p1[-1]=*(p1-1),1 2 3 4 未知a p-1 &a+1注意&a+1与 阅读全文
posted @ 2020-02-04 10:51 wuqi1003 阅读(140) 评论(0) 推荐(0) 编辑
摘要: struct Test{int num;char *pc;short data;char c[2];short sa[4]} *p;假设p的值为0x10000,问p+0x1=?(unsigned long)p+0x1=?(unsigned int*)p+0x1=?解析:p+1=sizeof(stru 阅读全文
posted @ 2020-02-04 10:50 wuqi1003 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 先推断一个程序的结果:int a[3][2]={(0,1),(2,3),(4,5)};int *p=a[0];printf("%d",p[0]);问打印结果?解析:花括号{}内是小括号(),应该先计算括号表达式的值。括号表达式计算顺序是从左到右,最终以最右边表达式的值作为整个表达式终值。所以(0,1 阅读全文
posted @ 2020-02-04 10:49 wuqi1003 阅读(167) 评论(0) 推荐(0) 编辑
摘要: int a[5][4]; int (*p)[4],(*q)[4]; p=a;//pq不是4的话,a就不能赋给p,//5可以是任意值不用理会。 阅读全文
posted @ 2020-02-04 10:48 wuqi1003 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 程序一:struct student{char *name;int score;} stu,*pstu;int main(){strcpy(stu.name,"Jimy");stu.score = 99;return 0;}问程序有何错误?答:错误在于struct中只是定义了指针name,并未分配空 阅读全文
posted @ 2020-02-04 10:37 wuqi1003 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 程序一: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) 编辑