Chapter 2 Introducing C-Review Questions

本文深入讲解C语言的基本概念,包括程序模块、语法错误、语义错误等关键知识点,并通过实例演示了如何正确编写C程序,解析了变量声明、赋值及输出语句的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.What are the basic module of a C program called?

They are called functions.

2.What is a syntax error? Give an example of one in English and one in C.

A syntax error is a violation of the rules governing how sentences or programs are put together. Here's an example in English:"Me speak English good." Here's an example in C.

printf"Where are the parentheses?";

3.What is a semantic error? Give an example of one in English and one in C.

A semantic error is one of meaning. Here's an example in English : " This sentence is excellent Czech."  Here's a C example:

thrice_n = 3 + n;

4.Indiana Sloth has prepared the following program and brought it to you for approval. Please help him out. 

Line 1: Begin with a #; spell the file stdio.h; place the filename within angle brackets.

Line 2: Use() , not {}; end the comment with */, not /*.

Line 3: Use {, not (.

Line 4: Complete the statement with a semicolon.

Line 5: Indiana got this one (the blank line) right!

Line 6: Use =, not := for assignment.(Apparently, Indiana knows a little Pascal.) User 52, not 56, weeks per year.

Line 7: Should be

printf("There are %d weeks in a year.\n", s);

Line 8: There isn't a line 9, but there should be, and it should consist of the closing brace, }.

5.  Assuming that each of the following examples is part of a complete program, what will each one print? 

     a. printf("Baa Baa Black Sheep.");

         printf("Have you any wool?\n");  

     b. printf("Begone!\nO creature of lard!\n");  

     c. printf("What?\nNo/nfish?\n");  

     d. int num;      

        num = 2;    

        printf("%d + %d = %d", num, num, num + num);     

a: Baa Baa Black Sheep.Have you any wool? (Note that there's no space after the period. You could have had a space by using " have instead of "have.)

b: Begone!

    O creature of lard! (Note that the cursor is left at the end of the second line.)

c: What?

    No/nfish? (Note that the slash[/] does not have the same effect as the backslash [\]; it simply prints as a slash.)

6.    Which of the following are C keywords?  main ,  int ,  function ,  char ,  =    

int and char. 

7.    How would you print the values of the variables  words  and  lines  so they appear in the following form: 
     

       There were 3020 words and 350 lines.   
 
       Here,  3020  and  350  represent the values of the two variables. 

printf("There were %d words and %d lines.\n", words, lines);

8.    Consider the following program: 

#include <stdio.h>

int main(void) {
    int a, b;

    a = 5;
    b = 2;    /* line 7 */
    b = a;    /* line 8 */
    a = b;    /* line 9 */
    printf("%d %d\n", b, a);
    return 0;
}

 What is the program state after line 7? Line 8? Line 9? 

After line 7, a is 5 and b is 2. After line 8, both a and b are 5. After line 9, both a and b are still 5. (Note that a cant be 2 because by the time you say a = b; b has already been changed to 5.)

 9.    Consider the following program: 

#include <stdio.h>

int main(void) {
    int x, y;

    x = 10;
    y = 5;          /* line 7 */
    y = x + y;      /* line 8 */
    x = x * y;      /* line 9 */
    printf("%d %d\n", x, y);
    return 0;
}

What is the program state after line 7? Line 8? Line 9? 

After line 7, x is 10 and y is 5. After line 8, x is 10 and y is 15. After line 9, x is 150 and y is 15.

Linux block IO(块输入输出)是Linux操作系统的IO子系统,用于管理块设备(例如硬盘和SSD)的访问。在多核系统上引入多队列SSD访问是一种优化措施。 传统上,Linux操作系统在处理块设备访问时,使用单个队列(queue)来处理所有IO请求。这种单队列设计对于单核系统来说是合适的,因为只有一个CPU核心可以处理IO请求。然而,在多核系统中,这种设计却成为了性能瓶颈,因为所有的IO请求都必须经过单个队列,即使有多个CPU核心是可用的。 为了解决这个问题,Linux引入了多队列SSD访问功能。这意味着在多核系统上,每个CPU核心都有一个独立的队列来处理IO请求。每个队列可以独立处理IO请求,而不会受到其他队列的干扰。这种设计可以提高系统的并发性和吞吐量。 多队列SSD访问还可以充分利用SSD设备的性能特点。SSD设备通常具有多个通道(channel)和多个闪存芯片(chip),每个通道和芯片都可以同时处理IO请求。通过将IO请求分配给多个队列,可以同时利用多个通道和芯片,从而提高SSD的性能。 在Linux中实现多队列SSD访问需要对内核进行相应的修改和配置。用户可以通过命令和配置文件来设置每个队列的属性和参数,以满足特定场景下的需求。 总之,通过引入多队列SSD访问,Linux在多核系统上可以更好地利用硬件资源,提高系统的性能和吞吐量。这是一个重要的优化措施,可以提高块设备访问的效率和响应速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值