栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C primer plus 2.11复习题

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C primer plus 2.11复习题

  1. C语言的基本模块是什么? 函数

  2. 什么是语法错误?写出一个英语例子和C语言例子 语法错误违反了组成语句或程序的规则 略

  3. 什么是语义错误?邪乎一个英语例子和C语言例子 语义错误是指含义错误

  4. Indiana Sloth编写了下面的程序,并征求你的意见。请帮助他评定。

    #include stdio.h
    ​
    int main{void} 
    (
        int s
        
    s := 56;
    printf(There ars s weeks in a year.);
    return 0;
    ​
    //下面修改
        
    #include
    int main(void)
    {
        int s;
        s = 56;
        printf("There are %d weeks in a year.",s);
        
        return 0;
    }
        
    ​

    5.

    假设下面的4个例子都是完整程序中的一部分,它们都输出什么结果?

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

    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);


    Baa Baa Black Shep.Have you any wool?

    Begone

    O creature of lard!

    What

    No/nfish?

    ** 2 + 2 = 4


    6.

    在main、int、function、char、= 中,哪些是C语言关键字?

    int、char

    main 是函数名,function是函数的意思 , = 是运算符
     

    7.如何以下面的格式输出变量words和lines的值?

    There were 3020 words and 350 lines.

    int words = 3020;
    ​
    int lines = 350;
    ​
    printf("There were %d words and %d lines", words, lines);

8.

考虑下面的程序:

#include 
int main(void)
{
    int a, b;
    
​
a = 5;
b = 2;  
b = a;  
a = b;  
printf("%d %dn", a, b);
return 0;
​
}

代码分析:

第4行处声明了两个变量a和b

第6行,将值5赋给变量a,此时 a = 5,b由于未赋初值,暂不确定

第7行,将值2赋给变量b,此时a = 5, b = 2

第8行,将变量a的值赋给变量b,即将值5赋给变量b,此时 a = 5, b = 5

第9行,将变量b的值赋给变量a,即将值5赋给变量a,此时a = 5, b = 5

因此最终printf()函数输出 5 5。

VS运行结果如下:

9、考虑下面的程序:

#include 
int main(void)
{
    int x, y;
    
​
    x = 10;
    y = 5;      
    y = x + y;  
    x = x * y;  
    printf("%d %dn", x, y);
    return 0;
​
}

请问,在执行完第7,第8,第9行后,程序的状态分别是什么?

代码分析:

第4行处声明了两个变量x和y

第6行,将值10赋给变量x,此时 x = 10,y由于未赋初值,暂不确定

第7行,将值5赋给变量y,此时x = 10, y = 5

第8行,先计算表达式x + y的值,即 10 + 5 = 15,将值15赋值给y,此时x = 10, y = 15

第9行,先计算表达式x * y的值,即 15 * 10 = 150,将值150赋值给x,此时x = 150, y = 15

因此最终printf()函数输出 150 15。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/913429.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号