演習3.433.44 3.45

演習3.43

int main()
{
    
    
	constexpr size_t row = 3, col = 4;
	int ia[row][col] = {
    
     1,2,3,4,5,6,7,8,9,10,11,12 };

	for (int(&p)[4] : ia)
	{
    
    
		for (int q : p)
			cout << q << ' ';
		cout << endl;
	}
	
	for (size_t i = 0; i != row; ++i)
	{
    
    
		for (size_t j = 0; j != col; ++j)
			cout << *(*(ia + i) + j) << ' ';//ia[i][j]
		cout << endl;
	}

	for (int(*p)[4] = ia; p != ia + 3; ++p)
	{
    
    
		for (int* q = *p; q != *p + 4; ++q)
			cout << *q << ' ';
		cout << endl;
	}
}

演習3.44

int main()
{
    
    
	constexpr size_t row = 3, col = 4;
	int ia[row][col] = {
    
     1,2,3,4,5,6,7,8,9,10,11,12 };

	using int_array = int[4];
	typedef int int_array[4];
	for (int_array& p : ia)
	{
    
    
		for (int q : p)
			cout << q << ' ';
		cout << endl;
	}

	for (int_array* p = ia; p != ia + 3; ++p)
	{
    
    
		for (int* q = *p; q != *p + 4; ++q)
			cout << *q << ' ';
		cout << endl;
	}
}

演習3.45

int main()
{
    
    
	constexpr size_t row = 3, col = 4;
	int ia[row][col] = {
    
     1,2,3,4,5,6,7,8,9,10,11,12 };

	for (auto& p : ia)
	{
    
    
		for (auto q : p)
			cout << q << ' ';
		cout << endl;
	}

	for (auto i = 0; i != 3; ++i)
	{
    
    
		for (auto j = 0; j != 4; ++j)
			cout << ia[i][j] << ' ';
		cout << endl;
	}

	for (auto* p = ia; p != ia + 3; ++p)
	{
    
    
		for (auto q = *p; q != *p + 4; ++q)
			cout << *q << ' ';
		cout << endl;
	}
}

おすすめ

転載: blog.csdn.net/Xgggcalled/article/details/109451803