C Language Computer Level 2/C Language Final Exam Questions (14) Pointer Topics

Collection of some classic C language computer level two and C language final exam question bank

It's not easy to organize, please like and collect to support

I wish you all high scores in the second-level computer and final exams

Series of articles:

C Language Computer Level 2/C Language Final Exam Questions (1)

C Language Computer Level 2/C Language Final Exam Questions (2)

C Language Computer Level 2/C Language Final Exam Questions (3)

C Language Computer Level 2/C Language Final Exam Questions (4)

C Language Computer Level 2/C Language Final Exam Questions (5)

C Language Computer Level 2/C Language Final Exam Questions (6)

C Language Computer Level 2/C Language Final Exam Questions (7)

C Language Computer Level 2/C Language Final Exam Questions (8)

C Language Computer Level 2/C Language Final Exam Questions (9)

C Language Computer Level 2/C Language Final Exam Questions (10) Function Topics

C Language Computer Level 2/C Language Final Exam Questions (11) Topics on Data Types and Input and Output

C Language Computer Level 2/C Language Final Exam Questions (12) Array Topic 1

C Language Computer Level 2/C Language Final Exam Questions (13) Array Topic 2

Table of contents

1. Fill in the blanks, 5 questions in total (5 points in total)

2. Judgment 5 questions in total (total 5 points)

3. Single choice, a total of 15 questions (total 15 points)

4. Procedure to fill in the blanks, 2 questions in total (20 points in total)

5. Program error correction 1 question in total (20 points in total)

6. Program design 1 question in total (25 points in total)


1. Fill in the blanks, 5 questions in total (5 points in total)

Question 1

In a C program, the pointer can be moved by three operations, they are [1], [2], [3].

=======(Answer 1)=======

self-increment

========= or =========

++

=======(Answer 2)=======

Decrement

========= or =========

--

=======(answer 3)=======

p+n

========= or =========

p-n

========= or =========

add or subtract a constant

Question 2

Suppose P is a pointer to A, Y is an integer variable, A=5, the address of A is EFO3; B=6, the address of B is EFO4; the result of P after executing the statement P=&A is [1].

=======(Answer 1)=======

EFO3

Question 3

After executing the following statement, the value of *(p+1) is 【1】.

 char  s[3]="ab",*p;

 p=s;

=======(Answer 1)=======

b

Question 4

In the c program, only NULL value and [1] value can be assigned to the pointer.

=======(Answer 1)=======

address

Question 5

The pointer of the variable, its meaning refers to [1] of the variable.

=======(Answer 1)=======

address

2. Judgment 5 questions in total (total 5 points)

Question 1

The statement that assigns the address of the variable whose subscript is i in the one-dimensional double-precision real number array x to the pointer variable p is:

double *p,x[10];int i=5;p=&x[i];

Answer: Y

Question 2

char (*p)[6]; If the p value is 1000, then p++; the final p value is 1006.

Answer: Y

Question 3

A pointer is the address of a variable.

Answer: Y

Question 4

If there is int a[10], *p;p=&a[5]; then p[-1] is legal.

Answer: Y

Question 5

The statement to assign the entry address of the function fun to the pointer variable p is p=fun;

Answer: Y

3. Single choice, a total of 15 questions (total 15 points)

Question 1

If there is int a[][2]={ {1,2},{3,4}}; then the meanings of *(a+1),*(*a+1) are ().

A:非法,2

B:&a[1][0],2

C:&a[0][1],3

D:a[0][0],4

Answer: B

Question 2

If there is an explanation: int i, j=2, *p=&i;, then the statement that can complete the i=j assignment function is ().

A:i=*p;

B:*p=*&j;

C:i=&j;

D:i=**p;

Answer: B

Question 3

If the array name is used as the actual parameter and the pointer variable is used as the formal parameter, the actual parameter of the function call is passed to the formal parameter ().

A:数组的长度

B:数组第一个元素的值

C:数组所有元素的值

D:数组第一个元素的地址

Answer: D

Question 4

If there is a definition: char *p1, *p2, *p3, *p4, ch; the program statement that cannot be assigned correctly is ().

A:p1=&ch; scanf("%c",p1);

B:p2=(char *)malloc(1);scanf("%c",p2);

C:*p3=getchar();

D:p4=&ch;*p4=getchar();

Answer: C

Question 5

int a[10]={1,2,3,4,5,6,7,8};int *p;p=&a[5]; the value of p[-3] is ().

A:2

B:3

C:4

D:不一定

Answer: B

Question 6

If there is int *p=(int *)malloc(sizeof(int)); then the statement to apply to the memory to store the integer 123 in the memory space is ().

A:scanf("%d",p);

B:scanf("%d",&p);

C:scanf("%d",*p);

D:scanf("%d",**p);

Answer: A

Question 7

It is known that p and p1 are pointer variables, a is an array name, and j is an integer variable. The incorrect one in the following assignment statement is ().

A:p=&j,p=p1;

B:p=a;

C:p=&a[j];

D:p=10;

Answer: D

Question 8

In the following definition statement, the error is ().

A:int a[]={1,2};

B:char *a[3];

C:char s[10]="test";

D:int n=5,a[n];

Answer: D

Question 9

char *s1="hello",*s2;s2=s1;then().

A:s2指向不确定的内存单元

B:不能访问"hello"

C:puts(s1);与puts(s2);结果相同

D:s1不能再指向其它单元

Answer: C

Question 10

If there is int a[10]={0,1,2,3,4,5,6,7,8,9}, *p=a; then the statement whose output result is not 5 is ().

A:printf("%d",*(a+5));

B:printf("%d",p[5]);

C:printf("%d",*(p+5));

D:printf("%d",*p[5]);

Answer: D

Question 11

If there is int i=3, *p;p=&i; in the following statement, the output result is 3 ().

A:printf("%d",&p);

B:printf("%d",*i);

C:printf("%d",*p);

D:printf("%d",p);

Answer: C

Question 12

If there is an explanation: int *p, m=5, n; the following correct program segment is ().

A:
p = &n;
scanf("%d", &p);

B:
p = &n;
scanf("%d,*p);

C:
scanf("%d", &p);
*p = n;

D:
p = &n;
*p = m;

Answer: D

Question 13

char *match(char c) is().

A:函数定义的头部

B:函数预说明

C:函数调用

D:指针变量说明

Answer: A

Question 14

Let char *s="\ta\017bc"; then the number of bytes occupied by the character string pointed to by the pointer variable s is ().

A:9

B:5

C:6

D:7

Answer: C

Question 15

If the variable is defined as "int x, *p=&x;", then &(*p) is equivalent to ().

A:p

B:*p

C:x

D:*(&x)

Answer: A

4. Procedure to fill in the blanks, 2 questions in total (20 points in total)

Question 1

题目:使用指向变量的指针编写交换两个变量值函数,按主调函数的调用形式编写。
void swap();
void main()
{
	int x, y;
	printf("输入两个整数 x,y \n");
	scanf("%d%d", &x, &y);
	swap(&x, &y);
	printf("x=%dy=%d", x, y);
}
void swap(int* p, int* q)
{
	int t;
	t = *p;
	【 ? 】;
	【 ? 】;
}

Answer:

=======(答案1)=======
*p=*q

=======(答案2)=======
*q=t

Question 2

题目:给定程序中,函数fun的功能是:调用随机函数产生20个互不相同的整数
     放在形参a所指数组中(此数组在主函数中已置0)。
#include <stdlib.h>
#include <stdio.h>
#define N  20
void fun(int* a)
{
	int i, x, j = 0;
	x = rand() % 20;
	while (j < 【 ? 】)
	{
		for (i = 0; i < j; i++)
			if (x == a[i])
				【 ? 】;
		if (i == 【 ? 】)
		{
			a[j] = x;
			j++;
		}
		x = rand() % 20;
	}
}

main()
{
	int x[N] = { 0 }, i;
	fun(x);
	printf("The result :  \n");
	for (i = 0; i < N; i++)
	{
		printf("%4d", x[i]);
		if ((i + 1) % 5 == 0)
			printf("\n");
	}
	printf("\n\n");
}

Answer:

=======(答案1)=======
N
=========或=========
20

=======(答案2)=======
break

=======(答案3)=======
j

5. Program error correction 1 question in total (20 points in total)

Question 1

功能:输入一个字符串,过滤此串,滤掉字母字符,并统计新生
     成串中包含的字符个数。

例如:输入的字符串为ab234$df4,则输出为:
     The new string is 234$4
     There are 5 char in the new string.
#include <stdio.h>
#include <conio.h>
#define N 80
int fun(char* ptr)
{
	int i, j;
	for (i = 0, j = 0; *(ptr + i) != "\\0"; i++)
		if (*(ptr + i) > 'z' || *(ptr + i) < 'a' || *(ptr + i) > 'Z' || *(ptr + i) < 'A')
		{
			(ptr + j) = (ptr + i);
			j++;
		}
	*(ptr + j) = '\0';
	return(j);
}

main()
{
	char str[N];
	int s;
	printf("input a string:"); gets(str);
	printf("The original string is :"); puts(str);
	s = fun(str);
	printf("The new string is :"); puts(str);
	printf("There are %d char in the new string.", s);
}

Answer:

=======(答案1)=======
for(i=0,j=0;*(ptr+i)!='\0';i++)

=======(答案2)=======
if(*(ptr+i)>'z'|| *(ptr+i)<'a'&&*(ptr+i)>'Z'||*(ptr+i)<'A')
=========或=========
if(*(ptr+i)<'A'|| *(ptr+i)>'Z'&&*(ptr+i)<'a'||*(ptr+i)>'z')

=======(答案3)=======
*(ptr+j)=*(ptr+i);

6. Program design 1 question in total (25 points in total)

Question 1

题目:编写函数fun,其功能是:将a、b两个两位正整数合并成一个新的整数放在c中。
     合并的方式是:将a中的十位和个位数依次放在变量c的千位和十位上,b中的十
     位和个位数依次放在变量c的个位和百位上。

例如:当a=45,b=12,调用该函数后c=4251。
#include <stdio.h>
void fun(int a, int b, long* c)
{
	/**********Program**********/



	/**********  End  **********/
}
void main()
{
	int a, b; long c;
	printf("Input a, b:");
	scanf("%d%d", &a, &b);
	fun(a, b, &c);
	printf("The result is: %ld\n", c);
}

Answer:

* c = b / 10 + (a % 10) * 10 + (b % 10) * 100 + (a / 10) * 1000;

If you have any mistakes or questions, please leave a message in the comment area for discussion.

Guess you like

Origin blog.csdn.net/qq_57342311/article/details/129891648