C++Primer第五版:练习3.34 3.35 3.36

练习3.34
p1加上p2到p1的距离,p2是尾后指针时非法

练习3.35

#include<iostream>
using namespace std;

int main()
{
    
    
	int a[] = {
    
     1,2,3 };
	auto* p1 = a, * p2 = end(a);

	while (p1 != p2)
		*p1++ = 0;
}

练习3.36

#include<iostream>
#include<vector>
using namespace std;

int main()
{
    
    
	int a[3] = {
    
     1,2,3 };
	int b[3] = {
    
     2,3,4 };

	if (end(a) - begin(a) != sizeof(b)/sizeof(*b))
	{
    
    
		cout << "not equal";
		return 0;
	}
	for(size_t i=0;i!=3;++i)
		if (a[i] != b[i])
		{
    
    
			cout << "not equal";
			return 0;
		}
	cout << "equal";
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Xgggcalled/article/details/109149591
今日推荐