当前位置:网站首页>【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
边栏推荐
- 递归函数中 有两个递归入口的时间复杂度
- PHP 多任务秒级定时器的实现方法
- Interview difficulties: difficulties in implementing distributed session, this is enough!
- Database SQL language practice
- Learn about spark project on nebulagraph
- Cdga | how to build data asset catalogue?
- Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
- Acquisition of bidding information
- Realize channel routing based on policy mode
- Leetcode:940. How many subsequences have different literal values
猜你喜欢

Solve vagrant's error b:48:in `join ': incompatible character encodings: GBK and UTF-8 (encoding:: Compatib

redis 哨兵集群搭建

金仓数据库 KingbaseES SQL 语言参考手册 (7. 条件表达式)

Cdga | how to build data asset catalogue?

Kingbasees SQL language reference manual of Jincang database (7. Conditional expression)

Operating steps for uninstalling the mobile app

Jdbc流式查询与游标查询

VS中使用动态库

Using dynamic libraries in VS

金仓数据库 KingbaseES SQL 语言参考手册 (6. 表达式)
随机推荐
flex布局
1.12 Web开发基础
金仓数据库 KingbaseES SQL 语言参考手册 (9. 常见DDL子句)
递归函数中 有两个递归入口的时间复杂度
金仓数据库 KingbaseES SQL 语言参考手册 (5. 操作符)
解决Vagrant报错b:48:in `join‘: incompatible character encodings: GBK and UTF-8 (Encoding::Compatib
Embedded sharing collection 14
Traversal of the first, middle, and last order of a binary tree -- Essence (each node is a "root" node)
光量子里程碑:6分钟内解决3854个变量问题
K. Link with Bracket Sequence I dp
1.12 basis of Web Development
Solution to slow download speed of vagrant
L. Link with Level Editor I dp
Easycvr video square channel display and video access full screen display style problem repair
Learn about spark project on nebulagraph
[the most complete and detailed] ten thousand words explanation: activiti workflow engine
Solve vagrant's error b:48:in `join ': incompatible character encodings: GBK and UTF-8 (encoding:: Compatib
顺序查找,折半查找,分块查找 ~
Interview questions for software testing is a collection of interview questions for senior test engineers, which is exclusive to the whole network
Practice operation and maintenance knowledge accumulation