【C++】获取二维数组的行和列

every blog every motto: You will never know unless you try

0. 前言

简单记录,C++中获取二维数组行和列

1. 正文

#include<iostream>
using namespace std;

void test666()
{
    
    
	cout << "我是测试程序:" << endl;

	int arr[3][5] = {
    
    
		{
    
     1,0,1,0,1 },
		{
    
     1,1,1,0,1 },
		{
    
     0,0,0,0,1 }
	};

	int all = sizeof(arr)/sizeof(int);
	cout << "数组元素总数为:"<<all << endl;
	int column = sizeof(arr[0]) / sizeof(arr[0][0]);
	int row = all / column;
	
	cout << "数组的行:" << row << endl;
	cout << "数组的列:" << column << endl;

}

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/108242125