3.34
功能:将p2的值赋给p1
当p1是const point时,该操作是非法的。
3.35
#include<iostream>
using std::cout;
using std::endl;
int main()
{
int arr[10];
int *e = &arr[10];
for (int *b = arr; b != e; ++b) {
*b = 0;
}
// 验证
for (int x: arr) {
cout << x << endl;
}
return 0;
}
3.36
1
#include<iostream>
using std::cout;
using std::endl;
#include<iterator>
using std::begin;
using std::end;
int main()
{
// 默认相同类型
int arr1[10];
int arr2[7];
// 比较索引范围
int size_arr1 = end(arr1) - begin(arr1);
int size_arr2 = end(arr2) - begin(arr2);
if (size_arr1 != size_arr2) {
cout << "Differen. " << endl;
return 0;
}
// 比较数组内容
for (int i = 0; i != size_arr1; ++i) {
if (arr1[i] != arr2[i]) {
cout << "Different. " << endl;
return 0;
}
}
cout << "Same arr. " << endl;
return 0;
}
2
#include<iostream>
using std::cout;
using std::endl;
#include<vector>
using std::vector;
int main()
{
vector<int> ivec{1, 2, 3};
vector<int> ivec2{1, 2, 3};
if (ivec == ivec2) {
cout << "Same vector. " << endl;
} else {
cout << "Different. " << endl;
}
return 0;
}