1.设有如下定义。
int arr[]={6,7,8,9,10}; int * ptr;
则下列程序段的输出结果为____。
ptr=arr; * (ptr+2)+=2; printf ("%d,%d\n",*ptr,*(ptr+2));
A.8,10
B.6,8
C.7,9
D.6,10
2.以下程序的输出结果是____。
main() { int i,k,a[10],p[3]; k=5; for (i=0;i<10;i++) a[i]=i; for (i=0;i<3;i++) p[i]=a[i*(i+1)]; for (i=0;i<3;i++) k+=p[i]*2; printf("%d\n",k); }
A.20
B.21
C.22
D.23
3.执行以下程序段后,m的值为____。
int a[2][3]={ {1,2,3},{4,5,6} }; int m,*p; p=&a[0][0]; m=(*p)*(*(p+2))*(*(p+4));
A.15
B.14
C.13
D.12
4.有以下程序。
main() { char a[]="programming", b[]="language"; char *p1,*p2; int i; p1=a; p2=b; for(i=0;i<7;i++) if(*(p1+i)==*(p2+i)) printf(" %c",*(p1+i)); }
输出结果是____。
A.gm
B.rg
C.or
D.ga
5.有以下程序。
void f(int *x,int *y) { int t; t=*x;*x=*y;*y=t; } main() { int a[8]={1,2,3,4,5,6,7,8},i,*p,*q; p=a;q=&a[7]; while(p) {f(p,q);p++;q--;} for(i=0;i<8;i++)printf("%d,",a[i]); }
程序运行后的输出结果是____。
A.8,2,3,4,5,6,7,1
B.5,6,7,8,1,2,3,4
C.1,2,3,4,5,6,7,8
D.8,7,6,5,4,3,2,1
6.有以下程序。
#include <STDIO.H struct stu { int num; char name[10]; int age; }; void fun(struct stu *p) { printf("%s\n",(*p).name); } main() {struct stu students[3]={ {9801,"Zhang",20}, {9802,"Wang",19}, {9803,"Zhao",18} }; fun(students+2); }
输出结果是____。
A.Zhang
B.Zhao
C.Wang
D.18
7.设有以下说明和定义。
typedef union { long i; int k[5]; char c; }DATE; struct date { int cat; DATE cow; double dog; } too; DATE max;
则下列语句的执行结果是____。
printf ("%d",sizeof (struct date ) +sizeof(max));
A.26
B.30
C.18
D.8
8.以下选项中,能定义s为合法的结构体变量的是____。
A.typedef struct abc
B.struct
{ double a ; { double a ; char b[10] ; char b[10] ; } s ; } s ;
C.struct ABC
D.typedef ABC
{ double a ; { double a ; char b[10] ; char b[10] ; } } ABC s ; ABC s ;
1.有以下定义和语句,则sizeof(a)的值是____,而sizeof(a.share)的值是____。
struct date { int day; int month; int year; union{ int share1 float share2; }share; }a;
2.若要使指针p指向一个double类型的动态存储单元,请填空。
p= malloc(sizeof(double));
3.下面程序的输出结果是____。
char b[]="abcd"; main() { char *chp; for(chp=b; *chp: chp+=2) printf("%s",chp); printf("\n"); }
4.以下程序的功能是:将无符号八进制数字构成的字符串转换为十进制整数。例如输入的字符串为556,则输出十进制整数366。请填空。
#include<stdio.h> main() { char *p, s[6]; int n; p=s; gets(p); n=*p-'0'; while( !='\0') n=n*8+*p-'0'; printf("%d \n",n); } }
1.使用指针实现将数组中的元素按照逆序存放。
2.编写一个求字符串子串的函数substr(char*str1,char str2[],int s,int m),要求将字符串str1从位置s开始的m个字符复制到字符串数组str2中。
3.递归实现函数,将一个整数转化为十进制数字输出。
4.约瑟夫环问题。13个人围成一圈,从第1个人开始报数,报到3退出圈子,按顺序输出退出圈子的序号。
5.一头刚出生的小牛,4年后生一头小牛,以后每年生一头。现有一头刚出生的小牛,问20年后共有牛多少头?
6.递归实现将一个字符串颠倒后重新存放在原字符串中。