C Language—Daily Multiple Choice Questions—Day50

        It has been updated day by day for 50 days. There are 250 selected questions. The blogger has done no less than 500 multiple-choice questions in total. His favorite question type is the calculation between pointers and arrays. I wonder if the friends who follow me have been insisting? There is a vote at the end of the article. You can vote to let the blogger know how long you lasted!

Question 1 (including operating system)

1. The following program outputs () "-"

#include <stdio.h>
int main() 
{
    int i;
    for (i = 0; i < 2; i++) 
    {
        fork();
        printf("-");
    }
    return 0;
}

A:2

B:4

C:6

D:8

Answer and analysis C

The fork function creates a child process. After fork, the parent process and the child process share code;

Therefore, in the first loop, the parent process outputs once and the child process outputs once;

In the second cycle, the parent process outputs once, the second child process outputs once; the child process outputs once, and the child process's child process outputs once, a total of 6 times;

Question 2

2. What is the result of sz()

struct Student 
{
    int num;
    char name[7];   
    short age;
    char sex;
} student1;
int sz = sizeof(student1);

A:14

B:15

C:16

D:20

Answer and analysis C

Memory alignment:C/C++ memory alignment rules (structure, union, class)-CSDN Blog

Question 3

3. The following statements: int *p, a = 10; p = &a;, all represent addresses ()

A: a p &a

B: &*a &a *p

C: *&p *p &a

D: &a p &*p

Answer and analysis D

Expressions for addresses include: p, &a, &*p

Question 4

4. After executing the following code, the output result is ()

#include <stdio.h>
int main() 
{
    int a[5]  = {1, 2, 3, 4, 5};
    int *ptr = (int*)(&a + 1);
    printf("%d, %d", *(a + 1), *(ptr - 1));
    return 0;
}

A:1,1

B:1,3

C:3,3

D:2,5

Answer and analysis D

Is this the second time this question has appeared? In-depth understanding: Dereference and addition of pointer variables - CSDN Blog

I hope you can draw your own pictures and show them in the comment area!

Question 5

5. When the following program is running, if you enter1abcedf2df<Enter>, what is the output result?

#include <stdio.h>
int main() 
{
    char a = 0, ch;
    while ((ch = getchar()) != '\n') 
    {
        if (a % 2 != 0 && (ch >= 'a' && ch <= 'z'))
            ch = ch - 'a' + 'A';
        a++;
        putchar(ch);
    }
    printf("\n");
    return 0;
}

A:1abcedf2df

B:1ABCEDF2DF

C:1AbCeDf2dF

D:1abceDF2DF

Answer and analysis C

        This question tests getchar. When we input, we entered 1abcedf2df<Enter>. These inputs will be stored in In the buffer, instead of directly inputting it into the input statement, the input statement in this question is getchar, which means getting one character at a time in the buffer, so the loop condition is to stop when getchar gets \n; then the if statement is the character ASCII-style odd number and lowercase character is converted to uppercase; finally putchar outputs the character;

ASCII value table:

Guess you like

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