当前位置:网站首页>【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
边栏推荐
- Jdbc流式查询与游标查询
- Servlet无法直接获取request请求中的JSON格式数据
- 日志收集分析平台搭建-1-环境准备
- Redis sentinel cluster setup
- Embedded sharing collection 15
- Operating steps for uninstalling the mobile app
- VRRP protocol and experimental configuration
- 二叉排序树(BST) ~
- 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
- EM and REM
猜你喜欢

Leetcode:940. How many subsequences have different literal values

PHP 多任务秒级定时器的实现方法

知识沉淀一:架构师是做什么?解决了什么问题

Sequential action localization | fine grained temporal contrast learning for weak supervised temporal action localization (CVPR 2022)

二叉树的前中后序遍历——本质(每个节点都是“根”节点)

What is spark serialization for?

“子问题的递归处理”——判断两棵树是不是相同的树——以及 另一颗树的子树

Concurrency opening -- take you from 0 to 1 to build the cornerstone of concurrency knowledge system

Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument

Leetcode:934. The shortest Bridge
随机推荐
Kingbasees SQL language reference manual of Jincang database (8. Functions (XI))
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
Etcd database source code analysis - cluster membership changes log
Solution to slow download speed of vagrant
Kingbasees SQL language reference manual of Jincang database (7. Conditional expression)
金仓数据库 KingbaseES SQL 语言参考手册 (11. SQL语句:ABORT 到 ALTER INDEX)
语法泛化三种可行方案介绍
【2023杰理科技提前批笔试题】~ 题目及参考答案
H. Take the Elevator 贪心
ament_cmake生成ROS2库并链接
Redis sentinel cluster setup
Youwei low code: Brick life cycle component life cycle
Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument
Recursive processing - subproblem
1.12 Web开发基础
基于消防GIS系统的智慧消防应用
K. Link with Bracket Sequence I dp
Distributed | practice: smoothly migrate business from MYCAT to dble
光量子里程碑:6分钟内解决3854个变量问题
Full binary tree / true binary tree / complete binary tree~