当前位置:网站首页>【Day04_0421】C语言选择题
【Day04_0421】C语言选择题
2022-07-26 06:08:00 【安河桥畔】
【Day04_0421】C语言选择题
1.有以下程序,程序运行后的输出结果是(C)
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int m = 0123;
int n = 123;
printf("%o %o\n", m, n);
return 0;
}
A 0123 0173
B 0123 173
C 123 173
D 173 173
解析:
0123表示八进制,%o表示以八进制打印输出,输出结果不显示0
2.以下哪个选项一定可以将flag的第二个bit置0(A)
A flag&=~2
B flag|=2
C flag^=2
D flag>>=2
3.请声明一个指针,其所指向的内存地址不能改变,但内存中的值可以被改变。(B)
A const int const *x = &y;
B int * const x = &y;
C const int *x = &y;
D int const *x = &y;
E const int * const x = &y;
4.以下C语言指令运行结果是什么?(C)
A 2,1
B 3,1
C 3,9
D 运行时崩溃
int a[5] = {
1,3,5,7,9 };
int* p = (int*)(&a + 1);
printf(“% d, % d”, *(a + 1),* (p - 1));
解析:
数组名除了在&和sizeof()符号下表示整个数组,其余情况都表示数组首元素地址
5.二维数组X按行顺序存储,其中每个元素占1个存储单元。若X[4][4]的存储地址为Oxf8b82140,X[9][9]的存储地址为Oxf8b8221c,则X[7][7]的存储地址为(A)。
A Oxf8b821c4
B Oxf8b821a6
C Oxf8b82198
D Oxf8b821c0
解析:
6.根据下面递归函数:调用函数Fun(2),返回值是多少(D)
int Fun(int n)
{
if (n == 5)
return 2;
else
return 2 * Fun(n + 1);
}
A 2
B 4
C 8
D 16
7.以下程序的输出结果是:(A)
#include <iostream>
using namespace std;
void func(char** m)
{
++m;
cout << *m << endl;
}
int main() {
static char* a[] = {
"morning", "afternoon", "evening" };
char** p;
p = a;
func(p);
return 0;
}
A afternoon
B 字符o的起始地址
C 字符o
D 字符a的起始地址
他的回答: (错误)
正确答案: A
解析:
1.a是一个指针数组,a中保存的时字符指针,在栈上开辟空间,其指向的字符串保存在静态字符常量区
2.对指针加1,相当于加上其所指向类型的大小,二级指针加一,则其指向下一个一级指针的位置
8.求函数返回值,输入x=9999(A)
int func(int x){
int count=0;
while (x)
{
count++;
x=x&(x-1);//与运算
}
return count;
}
A 8
B 9
C 10
D 12
解析:
x&x-1是统计一个数二进制中1的个数的方法,每次和比自己小1的数相与都会消去二进制中的一个1
9.下列程序执行后,输出的结果为()
#include<stdio.h>
int cnt = 0;
int fib(int n)
{
cnt++;
if (n == 0)
return 1;
else if (n == 1)
return 2;
else
return fib(n - 1) + fib(n - 2);
}
void main()
{
fib(8);
printf("%d", cnt);
}
A 41
B 67
C 109
D 177
解析:
cnt即递归调用的次数
10.在32位系统环境,编译选项为4字节对齐,那么sizeof(A)和sizeof(B)是:
struct A
{
int a;//4
short b;//2
int c;//4
char d;//1
};
struct B
{
int a;
short b;
char c;
int d;
};
A 16,16
B 13,12
C 16,12
D 11,16
解析:
short类型占2个字节内存,long类型占4个字节,结构体内存对齐
边栏推荐
- Practice operation and maintenance knowledge accumulation
- 金仓数据库 KingbaseES SQL 语言参考手册 (10. 查询和子查询)
- 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
- 数据库sql语言实战
- Kingbasees SQL language reference manual of Jincang database (8. Functions (XI))
- Database SQL language practice
- WebAPI整理
- 【BM2 链表内指定区间反转】
- 英语句式参考纯享版 - 状语从句
猜你喜欢

Unity2d animator cannot create transition

The time complexity of two recursive entries in a recursive function

Mysql45 talking about infrastructure: how is an SQL query executed?

Database SQL language practice
![[Oracle SQL] calculate year-on-year and month on month (column to row offset)](/img/ee/59d050e03c2a4ba04de57df1322283.png)
[Oracle SQL] calculate year-on-year and month on month (column to row offset)

Day110. Shangyitong: gateway integration, hospital scheduling management: Department list, statistics based on date, scheduling details

Leetcode:336. palindrome pair
C language explanation series - comprehensive exercises, guessing numbers games

Knowledge precipitation I: what does an architect do? What problems have been solved

Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument
随机推荐
Binary sort tree (BST)~
Establishment of log collection and analysis platform-1-environment preparation
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(十))
Kingbasees SQL language reference manual of Jincang database (6. Expression)
Can you make a JS to get the verification code?
Flex layout
[free and easy to use] holiday query interface
[the most complete and detailed] ten thousand words explanation: activiti workflow engine
Using dynamic libraries in VS
Day110. Shangyitong: gateway integration, hospital scheduling management: Department list, statistics based on date, scheduling details
Mysql45 talking about global lock, table lock and row lock
How to divide the disks under the devices and drives in win10 new computer
满二叉树 / 真二叉树 / 完全二叉树 ~
Docking wechat payment (II) unified order API
Leetcode:934. The shortest Bridge
CCTV dialogue ZTE: why must the database be in your own hands?
【(SV && UVM) 笔试面试遇到的知识点】~ phase机制
Etcd database source code analysis - cluster membership changes log
Xiao He shows his sharp corners and says hello to flutter app
Solutions to the failure of copy and paste shortcut keys


