Answer to Question #328400 in C++ for nickname

Question #328400

When a two-dimensional array is passed to a function, the parameter for the array must contain a constant or integer literal that represents the number of rows and columns.


A.True

B. False


1
Expert's answer
2022-04-16T03:46:20-0400
#include <iostream>

using namespace std;


const int N = 2,M=3;

void func1(int arr[N][M])
{
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cout << arr[i][j]<<" ";
		}
		cout << endl;
	}
}

void func2(int** arr)
{
	int *p_array = (int*)arr;
	for (int i = 0; i < 6; i++)
	{
		cout << p_array[i]<<" ";
		if (i == 2)cout << endl;
	}
}




int main() 
{
	int arr[2][3] = { {1,2,3},
				  {4,5,6} };
	func1(arr);
	func2((int**)arr);
	//Answer is False because it is not neccessary to pass constants
	//or literal, we can pass argument casted to pointer on pointer (arr**)
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS