美文网首页
C primer plus 第六版 第6版 003章 第三章 复

C primer plus 第六版 第6版 003章 第三章 复

作者: iOS开发章鱼哥 | 来源:发表于2017-03-21 21:07 被阅读396次

    1.指出下面各种数据使用的合适的数据类型(有些可使用多种数据类型)?

    a.East Simpletion的人口        int\short int\unsigned short

    b.DVD光盘的价格                float\double\

    c.本章出现次数最多的字母          char\

    d.本章出现次数最多的字母的次数   int \unsigned int

    2.在什么情况下要用long类型的变量代替int类型的变量?

    在系统中要表示的数超过了int可表示的范围,这是要使用long类型。

    如果要处理更大的值,那么使用一种在所有系统上都保证至少是32位的类型,可提高程序的可移植性。

    3.使用哪些可移植的数据类型可以获得32位有符号整数?选择的理由是什么?

    如果正好要获得32位的整数,可以使用int32_t类型。

    要获得可存储至少32位整数的最小类型,可以使用int_least32_t类型。

    如果要为32位整数提供最快的计算速度,可以选择int_fast32_t类型

    4.指出下列常量的类型和含义(如果有的话):

    '\b' char类型常亮 但是存储位int类型

    1066 int类型

    99.44 double类型

    0XAA 16进制int类型

    2.0e30  double类型

    5.Dittue Cawm编写了一个程序,请找出程序中的错误。

    #include

    (int) main {

    float g, h;

    float tax, rate;

    g = 1.e21   e前面至少要有一个数字;

    tax = rate*g;

    return 0;

    }

    6.写出下列常量在声明中使用的数据类型和在printf()中对应的转换说明:

    Constant                 Type                    Specifier

    12                         int                            %d

    0x3                     unsigned int                %#x

    'c'                     char                        %c

    2.34E07                 double                        %e

    '\040'                     char                        %c

    7.0                     double                        %f

    6L                         long int                    %ld

    6.0f                     float                        %f

    0x5.b6p12                 float                        %a

    7.写出下列常量在声明中使用的数据类型和在printf()中对应的转换说明(假设int为16位)

    Constant                 Type                    Specifier

    012                     int                        %#o

    2.9e05L                 long double                %le

    's'                     char                    %c

    100000                     long int                %ld

    '\n'                     char                    %c

    20.0f                     float                    %f

    0x44                     unsigned                %x

    -40                     int                        %d

    8.假设程序的开头有下列声明:

    int imate = 2;

    long short = 53456;

    char grade = 'a';

    float log = 2.71828;

    print("The odds against the %d were %ld to 1.\n",imagte, short);

    print("A score of %f is not an %c grade.\n",log, grade);

    9.假设ch是char类型的变量,分别使用转义序列、十进制值、八进制字符常量和十六进制字符常量把回车字符赋值给ch(假设使用ASCII编码值)

    转义字符 char ch=    '\r';

    十进制值 char ch='13'

    八进制 char ch='\015'

    十六进制 char ch='\xd'

    10.修正下列程序

    void main(int) /* this program is perfect */

    {

    int cows, legs;

    printf("How many cow legs did you count?\n");

    scanf("%d", legs);

    cows = legs / 4;

    printf("That implies there are %d cows.\n", cows)

    }

    11.指出下列转义序列的含义

    a. \n  换行

    b. \\  反斜杠

    c. \"  双引号

    d. \t  制表符

    相关文章

      网友评论

          本文标题:C primer plus 第六版 第6版 003章 第三章 复

          本文链接:https://www.haomeiwen.com/subject/rhxnnttx.html