一、选择题
2、对于static int a[3][4];则数组a中各元素在程序的编译阶段得到初值0.
6、int i=0,j=1,*p=&i,*q=&j;问错误的语句是( )
A) i=*&q; B) p=&*&i; C) *p++; D) i=*&j;
总结方法:从里到外层层剥离,碰到*&或者&*这种组合 抵消就行。
当然 得视情况而定,对于&*i 肯定是不对的,因为i不是一个指针变量,所以不能做*操作!
7、在递归函数中使用自动变量要十分小心,因为在递归过程中,不同层次的同名变量在赋值的时候可能会产生相互影响。
比如:
而对于递归回去的那个自动变量对每层的递归都有影响。
12、
至于答案为啥是B、丢失部分数据 我也不知道为啥。。。
13、关于#include 的第一个字符#开头的东西为编译预处理指令,但不是C语言的成分,其他语言也可以用这些指令。
l来自:http://c.biancheng.net/view/443.html
超过一行加一个\
..c为源代码,源代码执行完所有的所有的编译预处理指令后,形参中间代码文件.i->中间代码文件再通过C的编译器生成汇编代码文件.s->汇编代码文件去做汇编生成目标代码文件.o->汇编代码文件和其他东西连接后生成可执行文件.exe。
使用宏的注意事项:
练习:
二、
2、写出下面程序的功能(可举例说明程序的功能)
功能:
从命令行中输入两个字符串,一个是源串s,一个是目标串t;
再源串s中查找是否存在目标串t,若存在则返回t串所在s中的位置,若无则返回-1.
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int sub(char *p,char *q){ 5 int i; 6 char *p1=p,*q1; 7 for(i=0;*p;p++,i++){//真题中有错误,标红的地方真题写成了*p1,但是是不对的,而应是*p,琢磨一下就知道了。 8 p=p1+i; 9 if(*p!=*q) 10 continue; 11 for(q1=q+1,p=p+1;*p&&*q1;q1++,p++) 12 if(*p!=*q1) 13 break; 14 if(!(*q1)) 15 return i; 16 } 17 return -1; 18 } 19 20 21 int main(int argc,char *s[]) 22 { 23 int a; 24 a=sub(*(s+1),*(s+2)); 25 printf("%d",a); 26 return 0; 27 }
运行结果如下
3、下面程序由file1.c和file2.c组成,请写下面程序的输出结果。
file.c
1 /* 2 *file1.c 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 static int a=5; 7 int b=10; 8 extern void sub2(); 9 void sub1(){ 10 a+=2; 11 b+=3; 12 printf("%d %d\n",a,b); 13 } 14 int main() 15 { 16 sub1(); 17 sub2(); 18 sub1(); 19 sub2(); 20 printf("%d %d\n",a,b); 21 return 0; 22 }
1 /* 2 *file2.c 3 */ 4 #include<stdio.h> 5 static int a=10; 6 void sub2(){ 7 extern int b; 8 a+=10; 9 b+=2; 10 printf("%d %d\n",a,b); 11 }
运行结果
6、写出下面程序的输出结果
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 union node{ 5 int n; 6 int m; 7 }; 8 9 union node s[4]; 10 union node *p; 11 12 int main() 13 { 14 int n=1,i; 15 16 for(i=0;i<4;i++){ 17 s[i].n=n; 18 s[i].m=s[i].n+1; 19 n=n+2; 20 } 21 p=s; 22 printf("%d ",p->m); 23 ++p; 24 printf("%d\n",p->m); 25 return 0; 26 }
运行结果
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 void sub(int *pa,int *pb){ 5 int i; 6 for(i=0;i<3;i++) 7 printf("%d %d\n",*pa+++i,*pb+++i); 8 } 9 int main() 10 { 11 int a[10],b[10],*pa,*pb,i; 12 pa=a; 13 pb=b; 14 for(i=0;i<3;i++,pa++,pb++){ 15 *pa=i; 16 *pb=2**pa; 17 printf("%d %d\n",*pa,*pb); 18 } 19 sub(a,b); 20 return 0; 21 }
运行结果:
注意*pa++i <=>(*pa++)+i; 对于n=m+++n <=>n=(m++)+n;
8、写出下面程序的输出结果
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 struct str1{ 5 char *s; 6 char c[5]; 7 }; 8 int main() 9 { 10 struct str1 s1[2]={"ABCD","EFGH","IJK","LMN"}; 11 struct str2{ 12 struct str1 sr; 13 int d; 14 }s2={"OPQ","RST",0}; 15 struct str1 *p[2]; 16 p[0]=&s1[0]; 17 p[1]=&s1[1]; 18 printf("%s",++(*(p+1))->s); 19 printf("%c",s2.sr.c[2]); 20 return 0; 21 }
运行结果