C language homework (6)

1. The correct description of the following two-dimensional array a is (c).

A.int a[3][]

B.float a(3,4)

C.double a[1][4]

D.float a(3)(4)

2. To judge whether the string a is greater than b, you should use (D)

A.if (a>b)

B.if (strcmp(a,b))

C.if (strcmp(b,a)>0)

D.if (strcmp(a,b)>0)

3. There are the following procedures

main()
{ 
    int a=666,b=888;
    printf("%d\n",a,b);
}

The output after the program runs is ( 666 ).

error message

666

888

666,888
3. Among the following options, the one that cannot be used as an identifier is (D).
Identifier must not start with a number

A._1234_

B._1_2

C.int_2_

D.2_int_

4. In C++, what is used to implement dynamic polymorphism is (virtual function).

inline function

overloaded function

template function

virtual function

动态多态性:编译时无法立即确定其所要调用的同名函数,注意是同名函数,这才是多态的体现!要在运行时才能确定其要调用同名函数!
另一种静态多态:是在编译时就能被确定其要调用同名函数。
是能通过设立一个虚函数的方法,来动态确定要调用的同名函数。

5. The error of the following identifiers is (c)
the first part of the identifier cannot be a number

A.xly

B._123

C.2ab

D._ab

6. The following assignment statement that does not conform to C language syntax is (D).

A.a=1,b=2

B.++j;

C.a=b=5;

D.y=(a=3,6*5);

7. Among the following descriptions of C language functions, the correct one is (A).


A.C程序必须由一个或一个以上的函数组成

B.C 函数既可以嵌套定义又可以递归调用

C.函数必须有返回值,否则不能使用函数

D.C 程序中有调用关系的所有函数必须放在同一个程序文件中

8. Suppose x, y, and t are all int variables. After executing the following statement, the value of y is (3).
x=y=3; t=++x||++y;

uncertain

4

3

1
9. For the following program segment, the execution times of the loop body are: 2 times

y = 2;
while (y <= 8)
    y = y + y;

2
16
4
3
10. Use the variable a to give the following definition: an array of 10 pointers to a function that takes an integer parameter and returns an integer

A.int *a[10];

B.int (*a)[10];

C.int (*a)(int);

D.int (*a[10])(int);

11. Which of the following descriptions about java and c++ is wrong? (B)

JAVA does not support multiple inheritance

A.java是一次编写多处运行,c++是一次编写多处编译

B.c++和java支持多继承

C.Java不支持操作符重载,操作符重载被认为是c++的突出特征

D.java没有函数指针机制,c++支持函数指针

12. The statement that cannot assign the string "HELLO!" to the array b is (B)

A.char b[10]={‘H’,’E’,’L’,’L’,’O’,’!’,’\0’};

B.char b[10];b=”HELLO!”;//B here is the address, the first address of the array

C.char b[10];strcpy(b,”HELLO!”);

D.char b[10]=”HELLO!”;
13. Does *p++ increment p or the variable pointed to by p?// increment P, and then point to the variable pointed to before

auto increment p

the variable pointed to by incrementing p

Machine-related
14. What will the following program output: 1 2 2 2

static int a=1;
void fun1(void){    a=2;  }
void fun2(void){    int a=3;  }
void fun3(void){   static int a=4;  }
int main(int argc,char** args)
{
    printf(“%d”,a); 
    fun1( ); 
    printf(“%d”,a); 
    fun2( ); 
    printf(“%d”,a);
    fun3( );
    printf(“%d”,a); 
}

1 2 3 4

1 2 2 2

1 2 2 4

1 1 1 4
15. It is known that there are two statements in a normal running program: int p1,*p2=&a; p1=b; It can be seen that the types of variables a and b are (C) respectively.

A.intint

B.int*和int

C.intint*

D.int*和int*

16. In c++, when declaring const int i, at which stage is i only readable (when compiling)

compile

Link

run

None of the above is true
17. The result of the following program is (B)
int main(void)
{
printf(“%s , %5.3s\n”,”computer”,”computer”);
return 0;
}

A.computer , puter

B.computer , com

C.computer , computer

D.computer , compu.ter

18. After running the following C language program, the output on the screen is: A

void foobar(int a, int *b, int **c)
{
    int *p = &a;
    *p = 101;
    *c = b;
    b = p;
}

int main()
{
    int a = 1;
    int b = 2;
    int c = 3;
    int *p = &c;
    foobar(a, &b, &p);
    printf("a=%d, b=%d, c=%d, *p=%d\n", a, b, c, *p);
    return (0);
}
A.a=1, b=2, c=3, *p=2

B.a=101, b=2, c=3, *p=2

C.a=101, b=101, c=2, *p=3

D.a=1, b=101, c=2, *p=3

19. The running results of the following programs are 3, 5, please select the appropriate program for the horizontal line ( )

#include<stdio.h>
 struct S
 {
    int n;
    char c[10];
 } *p;
 main()
 {
    struct S a[3]={{3,"abc"},{5,"def"},{7,"ghi"}};
    p=a;
    printf("%d,",(*p).n);
    printf("%d\n",((*)(p+1)).n);
 }

20. The result of the following statement in C language is 1? B

A.main 函数正常结束的返回值

B.return 7&1;

C.char *p="hello"; return p == "hello";

D.上面都不对

21. In the following given program, the function of function fun is to store the odd numbers in the group indexed by the formal parameter a into a[0], a[1], a[2]... in the original order, and store the even numbers from Deleted from the array, the odd number is returned by the function value. For example, if the data in the group indexed by a is initially arranged as: 9,1,4,2,3,6,5,8,7, after deleting the even numbers, the data in the group indexed by a is: 9,1,3 ,5,7, the return value is 5.
Function prototype: int cnt_array_oushu(int *a, int len)

#include<stdio.h>
#define N 9;
int cnt_array_oushu(int *a, int len) 
{
    int *p = a;
    int arr[];
    int i = 0;
    int j = 0;
    for(i=0;i<len;i++)
    {
        if((a[i]%2) == 0)
        {
            arr[j] = a[i];
        }
        else
        {
            p = p + 1;
        }
    }

}
int main(void)
{
    int a[] = {9,1,4,2,3,6,5,8,7};
    int sum;
    sum = cnt_array_oushu(a, N) 
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325919564&siteId=291194637
Recommended