当前位置:网站首页>c语言学习回顾---1 基础知识回顾
c语言学习回顾---1 基础知识回顾
2022-06-10 17:31:00 【要努力丫!】
1、下面哪个不是C语言的内置的数据类型?
A、 char
B、double
C、struct Stu
D、short
2、局部变量的作用域是________A、main函数内部
B、整个程序
C、main函数之前
D、局部变量所在的局部范围
3、下面代码的输出结果是______
#include <stdio.h>
int num = 10;
int main()
{
int num = 1;
printf("%d\n",num);
return 0;
}
A、程序有问题,不能编译
B、输出1
C、输出10
D、输出0
4、字符串结束的标志是_______A、 ‘0’
B、EOF
C、‘\0’
D、空格
5、下面代码的结果是______
#include <stdio.h>
#include <string.h>
int main()
{
char arr[] = {
'c','a','t'};
printf("%d\n",strlen(arr));
return 0;
}
A、3
B、4
C、随机值
D、5
6、下面哪个不是转义字符?A、‘\n’
B、‘\060’
C、‘\q’
D、‘\b’
7、关于数组描述错误的是_____A、数组是一组相同类型元素的结合
B、数组的下标是从1开始的
C、数组的下标是从0开始的
D、数组如果初始化,可以不指定数组大小
8、C语言中哪个数组的创建是错误的?A、
int char[10]={0}B、
int n =10; int arr[n] = {0}C、
int arr[] ={1,2,3,4,5,6,7,8,9,0}D、
char ch[10]="hello"
9、下面代码的结果是?
#include <stdio.h>
#include <string.h>
int main()
{
printf("%d\n",strlen("c:\test\121"));
return 0;
}
- A、7
- B、8
- C、9
- D、10
10、编程:求两个数的较大值,写一个函数来求两个整数的较大值,如:输入10,20;输出较大值20.
int Max(int x, int y)
{
int m = x > y ? x : y;
return m;
/*if (x > y) return x; else return y;*/
}
int main()
{
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
int max = Max(a , b);
printf("较大值为:%d\n",max);
return 0;
}
运行结果如下:
25 35
较大值为:35
11、关于C语言的关键字说法正确的是____
A、关键字可以自己创建
B、关键字不能自己创建
C、关键字可以作变量名
D、typedef不是关键字
12、下面哪个不是关键字?A、 int
B、struct
C、define
D、continue
13、关于指针的说法正确的是______A、sizeof(char *)的大小一定是1
B、指针是个变量,用来存放地址
C、指针变量的大小都是4个字节
D、指针不是变量
14、关于static说法不正确的是______A、static可以修饰局部变量
B、static可以修饰全局变量
C、static修饰的变量不能改变
D、static可以修饰函数
15、下面代码的结果是什么
int sum(int a)
{
int c = 0;
static int b = 3;
c += 1;
b += 2;
return(a + b + c);
}
int main()
{
int i;
int a = 2;
for (i = 0; i < 5; i++)
{
printf("%d ",sum(a));
}
return 0;
}
A、6,8,10,12,14
B、8,10,12,14,16
C、10,12,14,16,18
D、12,14,16,18,20
16、用在Switch语言中的关键字不包含哪个?A、continue
B、break
C、default
D、case
17、牛客网—小飞机
KiKi学会了printf在屏幕输出信息,他想输出一架小飞机。请帮他编写程序输出这架小飞机。
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 2; i++)
{
printf(" ** \n");
}
for (i = 0; i < 2; i++)
{
printf("************\n");
}
for (i = 0; i < 2; i++)
{
printf(" * * \n");
}
return 0;
}
运行结果:
**
**
************
************
* *
* *
18、牛客网—被5整除
判断一个整数是否能5整除是一个挺简单的问题,懒惰的KiKi还是不想自己做,于是找到你帮他写代码,你就帮帮他吧。
#include <stdio.h>
int main()
{
printf("请输入一个数字(在0到100000之间):");
int M = 0;
scanf("%d", &M);
if (M % 5 == 0)
printf("YES");
else
printf("NO");
return 0;
}
请输入一个数字(在0到100000之间):20
YES
答案
1、C
2、D
如果在一个程序的开头声明一个变量:
void test()
{
int b = 0;
}
int main()
{
int a = 10;
return 0;
}
其中a与b都是局部变量,可知选项ABC都是错误的
3、B
考察局部变量与全局变量同名字的时候,局部变量优先
4、C
5、C
给其开辟一块空间存放’c’ ‘a’ ‘t’,但是不知道什么时候能遇到字符的结束标志,所以运行结果为随机值。
6、C
7、B
8、B
B选项中,n是变量,在创建数组的时候,指定n的大小,用的是常量。在c99标准中引用一个概念:变长数组,它支持数组创建的时候用变量指定大小,但是这个数组不能初始化。vs2019不支持c99中的变长数组。
9、A
\t以及\121都会被转义
11、B
12、C
define以及include都是预处理指令的符号
13、B
A选项char * 也是指针类型,指针类型的大小不是4个字节就是8个字节
D选项:通常意义上讲的都是指针变量
14、C
15、B
int sum(int a)
{
int c = 0;
static int b = 3;
c += 1;
b += 2;
return(a + b + c);
}
int main()
{
int i;
int a = 2;
for (i = 0; i < 5; i++)
{
printf("%d ",sum(a));
}
return 0;
}
该代码会循环执行5次,每执行一次都会调用sum函数,a最开始是2.将a送到int sum(int a)里面,a=2,c+=1,则c=1;b+=2,则b=5;所以第一次返回值是8。
i++执行之后,i变为1,再次进入循环;这一次,a依然是2,c再次变为0,b还是上次留下来的值,因为b被static修饰了。但是下一次进sum函数的时候,static int b = 3 就没有意义了。此时b已经是5了,5+2=7,所以2+1+7=10,直到i=5时退出循环,每一次循环时只有b在发生改变。
边栏推荐
猜你喜欢

Numpy - record

一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue

Chunk extend: hit training lab13

Noise line h5js effect realized by canvas

高数_第6章无穷级数__正项级数的性质

The development of flutter in digital life and the landing practice of Tianyi cloud disk

Abbexa 1,3-二棕榈素 CLIA 试剂盒解决方案

使用Canvas实现的噪音线条h5js特效

踩坑了,BigDecimal 使用不当,造成P0事故!

Wireshark学习笔记(一)常用功能案例和技巧
随机推荐
最新好文 | 基于因果推断的可解释对抗防御
The development of flutter in digital life and the landing practice of Tianyi cloud disk
How will you integrate into the $20trillion "project economy" in five years
玩转Pytorch的Function类
pands pd. Detailed parsing of dataframe() function
Cdga| six key points of data governance for industrial enterprises
CUDA编程(一):实现两个数组相加
Swin_Transformer源码解读
Can the "no password era" that apple is looking forward to really come true?
内存池原理一(基于整块)
系统需要把所有文件扫描一遍,并尝试识别视频的封面
Canvas fire burning H5 animation JS special effects
sense of security
Linear mobile chess
Abbexa 1,3-二棕榈素 CLIA 试剂盒解决方案
Red vertical left side menu navigation code
高数_第6章无穷级数__绝对收敛_条件收敛
搭建在线帮助中心,轻松帮助客户解决问题
Protocol Gen go grpc 'is not an internal or external command, nor is it a runnable program or batch file
Noise line h5js effect realized by canvas