Greetings,
sir I want to know the few piece of code which are not used before.
- what will int main(int argc, char const *argv[])
do? - int *arr= new int[n];
for( int i=0;i<n;i++){
arr[i]= new int[m];
}
Greetings,
sir I want to know the few piece of code which are not used before.
@Tanvi-Varshney-250726472940778,
int main(int argc, char const * argv[])
, here int argc, char const*argv[] are command line arguments, generally they are mostly used when you are using c++ for some development like game dev and so , you can use your normal int main()
you can learn more about the command line argument here :- https://www.geeksforgeeks.org/command-line-arguments-in-c-cpp/
int **arr= new int* [n];
for( int i=0;i<n;i++){
arr[i]= new int[m];
}
here ,we are dynamically allocating memory for a matrix of dimensions n*m
int ** arr= new int*[n];
you need to have knowledge of dynammic memory allocation for you to understand this , so if you don;t know about that , i will suggest you to brush up your basics on that topic first now , what we are doing here is we are dynamically allocating an array of integer pointers it returns the address of first pointer from the array of integer pointer so we need a pointer of integer pointer to store that that’s why we did int *arr instead of int ,
Inside for loop ,we are dynamically allocating an array of integers and storing the pointer returned to arr[i] ,
so we got a dynammically allocated integer matrix of size n
Instead of dynammically allocating matrix, you can simply allocate statically like
int arr[n][m];
In case of any doubt feel free to ask
Mark your doubt as RESOLVED if you got the answer
Thnku sir, I got it by the help of you
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.