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
#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**)
}
Comments
Leave a comment