字符数组知识点练习

以下是湖南省对口招生考试中涉及字符数组知识点的真题,供练习使用。

题目一:程序分析

阅读程序,写出运行结果:

#include <stdio.h> #include <string.h> int main() { char a[] = "ABCD", b[] = "BAD"; int i, j; for(i = 0; i < strlen(b); ++i) { for(j = 0; (j < strlen(a)) && (a[j] != b[i]); ++j) ; if(j >= strlen(a)) { printf("No"); return 0; } } printf("Yes"); return 0; }
参考答案:

点我显示

2022年
题目二:程序分析

阅读程序,写出运行结果:

#include <stdio.h> int main() { char s1[] = "! love China"; char s2[] = "! love"; char *str1 = s1, *str2 = s2; int answer = 0; while (!(answer = *str1 - *str2) && *str2) { str1++; str2++; } if (answer < 0) answer = 1; else if (answer > 0) answer = -1; printf("answer=%d \n", answer); return 0; }
参考答案:

点我显示

2020年
题目三:程序分析

阅读程序,写出运行结果:

#include <stdio.h> #include <string.h> int main() { char a[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', '\0'}; int x, y; x = sizeof(a); y = strlen(a); printf("%d %d\n", x, y); return 0; }
参考答案:

点我显示

2024年
题目四:程序分析

阅读程序,写出运行结果:

#include <stdio.h> #include <string.h> int main() { char s[10] = "abc"; char t[10] = "123"; char p[10] = "xyz"; strcpy(s + 1, t + 1); printf("string=%s", strcat(s, p + 1)); return 0; }
参考答案:

点我显示

2025年
题目五:程序分析

阅读程序,写出运行结果:

#include <stdio.h> int main() { char a = 5, b = 126; char c = a + b; printf("%d", c); return 0; }
参考答案:

点我显示

2024年
题目六:程序分析

若 "char a[6]="abced";",执行 "printf("%d%d",strlen(a),sizeof(a));" 后输出结果是:

参考答案:

5 6 (strlen计算字符串长度,sizeof计算数组大小)

2024年
题目七:程序分析

若 "char a[8]="1234"; int x=strlen(a), y=sizeof(a);" 则 x 和 y 的值分别是:

参考答案:

点我显示

2021年
题目八:程序分析

阅读程序,写出运行结果:

#include <stdio.h> int main() { char a, b; scanf("%c%*2c%c", &a, &b); printf("%c%c\n", a, b); return 0; }

若输入:12345

参考答案:

点我显示

2021年