C++ Primer Plus 第四章复习题答案
因为期末复习周和自己的懈怠荒废了好久。。。寒假就把这边书看完!干了兄弟们,奥利给
冲!
4.12 复习题
char actor[30]; short betsie[100]; float chuck[13]; long double dipsea[64];
arrary<char,30> actor; array<short,100> betsie; array<float,13>; array<long double,64> dipsea;
int arr[5] {1,3,5,7,9};
int even = arr[0] + arr[4];
cout<<ideas[1]<<endl;
char str1[] = "cheeseburger";
string str2 = "Waldorf Salad";
struct fish
{
char kind[30];
int weight;
double length;
}
fish a ={"shark",100,100.1};
enum Response{No,Yes,Maybe};
double *ptr = &ted;
cout<<*ptr<<endl;
float *ptr = treacle;
cout<<*ptr<<endl;//第一个元素
cout<<*(ptr+9)<<endl;//最后一个,注意是加9
int num;
cin>>num;
int *ptr = new int [num];
vector<int> vi(num);有效,打印出该字符串首字符的地址
struct fish{char name[10];int weight;double length;};
fish *ptr = new fish;
cin>>ptr->length;
cout<<ptr->weight<<endl;
delete ptr;第二句没有指明应该读取多少数据。所以address被分配的内存可能不够用来存放用户输入的数据,从而导致数组越界,发生程序崩溃或者某些不可预知的后果。
#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
我自己是看完每一章都会看一下里面的内容的,感兴趣的话家人们也可以去看一看。