C Language—Daily Multiple Choice Questions—Day61

Pointer related blogs

The first shot of pointer: pointer family-CSDN Blog

In-depth understanding: dereference and addition of pointer variables-CSDN Blog

first question

1. The content pointed to by the following pointer can be modified ()

A:const int* a

B:int const* b

C:int* const c

D:const int* const d

Answer and analysis  C

const is on the left side of *, and the content pointed to by the pointer cannot be modified;

const on the right side of *, the pointer itself cannot be modified

Question 2

2. Assume that variables a and b are both integers, and the expression value is ()

(a = 5, b = 2, a > b ? a++ : b++, a + b)

A:7

B:8

C:9

D:2

Answer and analysis  B

        This question examines a comma expression. The comma expression must calculate the result of each expression in turn, but the result of the comma expression is the result of the expression after the last comma. The reason for evaluating them sequentially is that the previous expressions will affect the result of the last expression.

Question 3

3. The output result of the following program is ( )

#include <stdio.h>
int main() 
{
    unsigned char a = 235;
    unsigned char b = ~a;
    unsigned char c = b >> 1;
    printf(“%d”, c);
}

A:6

B:2

C:4

D:10

Answer and  analysisD 

        This question examines bit operations on unsigned numbers. First of all, you must know that the highest bit of the binary bit of an unsigned number is the numerical bit, not the sign bit. Secondly, the char type has 1 byte and 8 bits;

a :1 1 1 0 1 0 1 1

b :   0 0 0 1 0 1 0 0

c : 0 0 0 0 1 0 1 0

c = 10

Question 4

4. With the following definitions, which expressions of the following options will be prohibited by the compiler () [Multiple choices]

int a = 248, b = 4;
int const c = 21;
const int *d = &a; 
int *const e = &b;
int const * const f = &a; 

A:*c=32

B:*d=43

C:e=&a

D:f=0x321f

E:d=&b

F:*e=34

Answers and analysis  ABCD

const is on the left side of *, and the content pointed to by the pointer cannot be modified;

const on the right side of *, the pointer itself cannot be modified

Question 5

5. The output of the following program is ()

#include <stdio.h>
struct HAR 
{
    int x,y;
    struct HAR *p;
} h[2];
int main()
{
    h[0].x = 1;
    h[0].y = 2;
    h[1].x = 3;
    h[1].y = 4;
    h[0].p = &h[1];
    h[1].p = h;
    printf("%d,%d \n", (h[0].p)->x, (h[1].p)->y);
}

A:1,2

B:2,3

C:1,4

D:3,2

Answer and  analysisD

This is an array of structures, and then they are assigned values ​​one by one. The result is as follows:

Accessed in the output statement:

Guess you like

Origin blog.csdn.net/2302_76941579/article/details/135162035