(C)一些题12

2023-12-13 16:39:49

1.

#include<stdio.h>
void main()
{
char s[]="123456";
printf("%d\n",strlen(s));
printf("%s\n",s);
printf("%d\n",sizeof(s));
}

答案:6

? ? ? ? ?123456

? ? ? ? ? ?7

2.


#include<stdio.h>
#include<string.h>

void main()
{
int a[]=(1, 5,9,4, 5,6,7,8,9,10】,*p=a;
printf("%d\n",sizeof(a));
printf("%d\n, sizeof(p));
printf("%d\n *p++);//*p++相当于*(p++)即先打印输出p所指向的单元的值再P++
printf("*p=%d\n",*p);
printf("%d\n",*++p); //*++p相当于*(++p)即先将p++,再打印出p指向的单元的值
printf("p=%d\n",*p);
printf("%d\n",(*p)++);//先打印出*p, 再将p指向的单元的值加1
//如p指向a[0]=1,则相当于先打印出a[0],再将a[0]+1
printf("*p=%d\n",*p);
printf("*p=%d\n",++*p) /++*p相当于++(*p),将配置项的单元的值加1后再打印出来printf("*p=%d\n",*p)
}

答案:

40
4
1
*p=5
9
*p=9
9
*p=10
*p=11

*p=11

3.

#include<stdio.h>
void main()
{
int p[8]={11,12, 13,14,15,16,17,18}, i=0,j=0;
while(i++<7)
if(p[i]%2) j+=p[i];
printf("%d\n",j);
}

答案:45

4.以下对枚举类型名的定义中正确的是(A)。
A.enum?a{fsum=9,mon=-1,tue};
B.enum?a=(sum,mon,tue};
C.enum?a{f"sum","mon","tue"};
D.enum?a={"sum","mon","tue"};


5.在下列程序段中,枚举变量c1的值是(D)。

enum?color {?red,yellow,blue=4,green,white}c1;

c1=white;
A.1?B.3?C.?5?D.6

解析:bblue为4,所以顺延
?

6.//要求逆序输出一个字符串,要求用递归完成

#include<stdio.h>
#include<string.h>
void main()
{
void reverse_str(char *p);
char str[80]="123456";
// gets(str);
 reverse_str(str);
}

void reverse_str(char *p)
{
if(*p)
{
char c;
reverse_str(p+1);
c=*p;
//putchar(*p);
}}

7.//判断一个字符串中()是否配对
?

//判断一个字符串中()是否配对
#include<stdio.h>
#include<string.h>
int match(char *str.int length)
void main()
{
char b[100];
char *s=b;
int len:
int m;
s="90d(jk)jk(ghy(23)ss)";
len=strlen(s)
m=match(s, len)
if(m)
printf("match!\n");
else
printf("no match!\n");
}

int match(char *str.int ength)
{
int i, count1=0, count2=0;
for(i=0;i<length;i++)
{
if(*(str+i)=='(')
count1++;
if(*(str+i)=')')
count2++;
}
if(count1==count2)
return 1;
else
return 0;
}

文章来源:https://blog.csdn.net/qq_53201950/article/details/134934006
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。