欢迎光临散文网 会员登陆 & 注册

C++ Primer Plus 第四章复习题答案

2022-01-21 19:51 作者:狱雷Guru  | 我要投稿

因为期末复习周和自己的懈怠荒废了好久。。。寒假就把这边书看完!干了兄弟们,奥利给

冲!


4.12  复习题

  1.   char actor[30];    short betsie[100];    float chuck[13];    long double dipsea[64];

  2.  arrary<char,30> actor;    array<short,100> betsie;    array<float,13>;                              array<long double,64> dipsea;

  3. int arr[5] {1,3,5,7,9};

  4. int even = arr[0] + arr[4];

  5. cout<<ideas[1]<<endl;

  6. char str1[] = "cheeseburger";

  7. string str2 = "Waldorf Salad";

  8. struct fish

    {

    char kind[30];

    int weight;

    double length;

    }

  9. fish a ={"shark",100,100.1};

  10. enum Response{No,Yes,Maybe};

  11. double *ptr = &ted;

    cout<<*ptr<<endl;

  12. float *ptr = treacle;

    cout<<*ptr<<endl;//第一个元素

    cout<<*(ptr+9)<<endl;//最后一个,注意是加9

  13. int num;
    cin>>num;
    int *ptr = new int [num];
    vector<int> vi(num);

  14. 有效,打印出该字符串首字符的地址

  15. struct fish{char name[10];int weight;double length;};
    fish *ptr = new fish;
    cin>>ptr->length;
    cout<<ptr->weight<<endl;
    delete ptr;

  16. 第二句没有指明应该读取多少数据。所以address被分配的内存可能不够用来存放用户输入的数据,从而导致数组越界,发生程序崩溃或者某些不可预知的后果。

  17. #include <vector>

    #include <string>

    #include <array>

    const int count = 10;

    std::vector<string> vs(count);

    std::array<string,10> as;


4.13 编程练习

编程练习的所有源代码我都放在了GitHub上

https://github.com/Lemy28/CPP-primer-plus_exercise


另外发现了GitHub上c++进阶的方向,好像是清华大佬的项目

github.com/Light-City/CPlusPlusThings

我自己是看完每一章都会看一下里面的内容的,感兴趣的话家人们也可以去看一看。



C++ Primer Plus 第四章复习题答案的评论 (共 条)

分享到微博请遵守国家法律