C/C++ 二维数组作为函数参数传递都会退化为指针

void printArray(int *array, int high, int wide)
{
	for (int i = 0; i < high; ++i)
	{
		for (int j = 0; j < wide; ++j)
		{
			cout << *(array + i*wide + j) << "  ";
		}
		cout << endl;
	}
	cout << endl;
}

int main()
{
	int array[3][2] = { 1, 2, 3, 4, 5, 6 };
	//比较下面三种传递的意思	
	printArray(*array, 3, 2);
	printArray(*(array + 0) + 0, 3, 2);
//	printArray(&array[0][0], 3, 2);

	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
//			cout << array[i][j] << "  ";
			cout << *(*(array + i) + j) << "  ";
		}
		cout << endl;
	}
    
    	system("pause");
    	return 0;
    }

发布了43 篇原创文章 · 获赞 1 · 访问量 2320

猜你喜欢

转载自blog.csdn.net/lpl312905509/article/details/101282010