Doubts regarding array definition

When I am running this code, it is showing expected result
#include
using namespace std;

int main()
{

int arr[5][3]={0};
//Iterate over the array
for(int rows=0;rows<=4;rows++)
{
	for(int cols=0;cols<=2;cols++)
	{
		cout<<arr[rows][cols];
	}
}

return 0;
}

However, if I run this code, the prompt returns to itself without showing any output, why? Is this related to time complexity?I am new to that.
#include
using namespace std;

int main()
{

int arr[1000][1000]={0};
//Iterate over the array
for(int rows=0;rows<=4;rows++)
{
	for(int cols=0;cols<=2;cols++)
	{
		cout<<arr[rows][cols];
	}
}

return 0;
}

hi @distyb04

int arr[1000][1000]={0};
//Iterate over the array
for(int rows=0;rows<=4;rows++)
{
	for(int cols=0;cols<=2;cols++)
	{
		cout<<arr[rows][cols];
	}
}

in this code u will get no o/p only becoz in array u can access elemets by position only…
like arr[i][j] while running loop… at this index where u are trying to print, there may be no element present so u get no o/p…

for printing the whole array use the first code only that u shared…

okay thnks understood

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.