Code syntax not understood

why are we using arguments to the main function?
and what is the below line’s purpose

char *arr=new int[n]
for(int i=0;i<n;i++)
{ arr[i]=new int[m];}

please explain

The variables are named argc (argument count) and argv (argument vector) by convention, but they can be given any valid identifier: int main ( int num_args, char arg_strings) is equally valid. They can also be omitted entirely, yielding int main () , if you do not intend to process command line arguments.
you can ignore it, NOT needed

allocation of 2D array dynamically
char arr=new int [m]
form this line we are making an array of size m which stores data of type int

means it stores address of integer array

so now we have to place addresses of array in this array
for that we write
char * arr=new int [n]
for(int i=0;i<m;i++)
{ arr[i]=new int[n];

this will help you

1 Like

sir i thanks for such an elaborated explanation but still didnt understand what does those vertical boxes do tell in the figure. what is implied by char*arr=new int[n]

char *arr=new int[n]
this will create an character array of size n
new keyword is used to allocate array dynamically

now what is 2D array?
array of arrays
means to make mXn 2D array what we will do
we make an array of size m which stores address of all arrays of size n

so the horizontal array is of size m which store address of all other n sized array which are vertical

i hope this help
Take your time and try to understand
i recommend you to watch videos on dynamic memory allocation as well
this will also help you

if you have more doubts then fell free to ask

1 Like

thank you very much all doubts resolved

1 Like