当前位置:网站首页>【Day02_0419】C语言选择题
【Day02_0419】C语言选择题
2022-07-26 06:08:00 【安河桥畔】
【Day02_0419】C语言选择题
1.使用printf函数打印一个double类型的数据,要求:输出为10进制,输出左对齐30个字符,4位精度。以下哪个选项是正确的?(C)
A %-30.4e
B %4.30e
C %-30.4f
D %-4.30f
解析:
%m.nf,m表示输出字符宽度,n表示保留精度,默认是右对齐,左对齐加’-’
2.请找出下面程序中有哪些错误(C)
int main()
{
int i = 10;
int j = 1;
const int* p1;//(1)
int const* p2 = &i; //(2)
p2 = &j;//(3)
int* const p3 = &i;//(4)
*p3 = 20;//(5)
*p2 = 30;//(6)
p3 = &j;//(7)
return 0;
}
A 1,2,3,4,5,6,7
B 1,3,5,6
C 6,7
D 3,5
解析:
const在*左边修饰*,表示指针指向的内容不能修改
const在*右边修饰指针变量,表示指针变量的指向不能修改
3.下面叙述错误的是()
char acX[] = ”abc”;
char acY[] = {
‘a’,’b’,’c’ };
char* szX = ”abc”;
char* szY = ”abc”;
A acX与acY的内容可以修改
B szX与szY指向同一个地址
C acX占用的内存空间比acY占用的大
D szX的内容修改后,szY的内容也会被更改
解析:
acX与acY在栈开辟空间,而szX和szY指向的字符串保存在静态字符常量区
szX是一个字符指针,修改其指向不会改变字符串
4.下列代码的运行结果是(C)
int a[]={
1,2,3,4};
int *b=a;
*b+=2;
*(b+2)=2;
b++;
printf(“%d,%d\n”,*b,*(b+2));
A 1,3
B 1,2
C 2,4
D 3,2
解析:
*b+=2; *优先级比+=高,所以*b+=2中b先和*结合,本条语句执行结果是将数组第一个元素的值+2
*(b+2)=2; 指针先向后偏移两个单位,再赋值
5.下列关于C/C++的宏定义,不正确的是(B)
A 宏定义不检查参数正确性,会有安全隐患
B 宏定义的常量更容易理解,如果可以使用宏定义常量的话,要避免使用const常量
C 宏的嵌套定义过多会影响程序的可读性,而且很容易出错
D 相对于函数调用,宏定义可以提高程序的运行效率
6.有以下定义:int a[10]; char b[80];函数声明为:void sss(char[], int[]); 则正确的函数调用形式是(D)。
A sss(a,b);
B sss(char b[],int a[]);
C sss(b[],a[]);
D sss(b,a);
7.用变量a给出下面的定义:一个有10个指针的数组,该指针指向一个函数,该函数有一个整形参数并返回一个整型数(D)
A int *a[10];
B int (*a)[10];
C int (*a)(int);
D int (*a[10])(int);
8.以下 C++ 函数的功能是统计给定输入中每个大写字母的出现次数(不需要检查输入合法性,所有字母都为大写),则应在横线处填入的代码为(D)
void AlphabetCounting(char a[], int n) {
int count[26] = {
}, i, kind = 10;
for (i = 0; i < n; ++i)
_________________;
for (i = 0; i < 26; ++i) {
printf("%c=%d", _____, _____);
}
}
A
++count[a[i]-‘Z’]
‘Z’-i
count[‘Z’-i]
B
++count[‘A’-a[i]]
‘A’+i
count[i]
C
++count[i]
i
count[i]
D
++count[‘Z’-a[i]]
‘Z’-i
count[i]
解析:
hash
9.在32位cpu上选择缺省对齐的情况下,有如下结构体定义,则sizeof(struct A)的值为(C)
struct A {
unsigned a : 19;
unsigned b : 11;
unsigned c : 4;
unsigned d : 29;
char index;
};
A 9
B 12
C 16
D 20
解析:
位段
4字节:19+11
4字节:4
4字节:29
1字节:8
struct内存对齐,16字节
10.下面代码会输出(A)
int main() {
int a[4] = {
1,2,3,4 };
int* ptr = (int*)(&a + 1);
printf("%d", *(ptr - 1));
}
A 4
B 1
C 2
D 3
边栏推荐
- Solutions to the failure of copy and paste shortcut keys
- 金仓数据库 KingbaseES SQL 语言参考手册 (10. 查询和子查询)
- 移动web
- Mysql45 talking about global lock, table lock and row lock
- Implementation of PHP multitask second timer
- Traversal of the first, middle, and last order of a binary tree -- Essence (each node is a "root" node)
- 二叉树的性质 ~
- Embedded sharing collection 15
- Learn about spark project on nebulagraph
- Full binary tree / true binary tree / complete binary tree~
猜你喜欢

Kingbasees SQL language reference manual of Jincang database (6. Expression)

对接微信支付(二)统一下单API

Kingbasees SQL language reference manual of Jincang database (8. Functions (XI))

Convolutional neural network (III) - target detection

Matlab 向量与矩阵

Introduction to three feasible schemes of grammatical generalization

How to divide the disks under the devices and drives in win10 new computer

vagrant下载速度慢的解决方法

Widget is everything, widget introduction

Solutions to the failure of copy and paste shortcut keys
随机推荐
Properties of binary tree~
Kingbasees SQL language reference manual of Jincang database (11. SQL statement: abort to alter index)
Redis sentinel cluster setup
What is spark serialization for?
【Oracle SQL】计算同比与环比(列转行进行偏移)
Print linked list in reverse order
Concurrency opening -- take you from 0 to 1 to build the cornerstone of concurrency knowledge system
Learn about spark project on nebulagraph
Servlet filter details
Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
K. Link with Bracket Sequence I dp
英语句式参考纯享版 - 状语从句
Solutions to the failure of copy and paste shortcut keys
Introduction of four redis cluster schemes + comparison of advantages and disadvantages
Ros2 knowledge: DDS basic knowledge
【(SV && UVM) 笔试面试遇到的知识点】~ phase机制
语法泛化三种可行方案介绍
递归处理——子问题
时序动作定位 | 用于弱监督时态动作定位的细粒度时态对比学习(CVPR 2022)
ETCD数据库源码分析——Cluster membership changes日志