Sir i am not able to understand way we are taking parameters in main() and why we are using pointers to pointer , can we do it by pointer only.
Implementation of sum of sub matrix
to allocate 2D dynamic array we need to use two pointer
single pointer can be used to make only 1D array
for better understanding
to allocate 2D array of size MXN dynamically
first we make array of size M this will store address of n sized m arrays
int * arr=new int [M]
now we make n sized m arrays
for(int i=0;i<m;i++){
arr[i]=new int[n];
}
i hope this picture will help you to understand well
you can also visit this doubt
Sir why we are taking parameters in main()
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.
these are Command-line arguments
Command-line arguments are given after the name of the program in command-line shell of Operating Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program
argv(ARGument Vector) is array of character pointers listing all the arguments.
int main(int argc, char argv[]) { / … */ }
or
int main(int argc, char * argv) { / … */ }
#include <iostream>
using
namespace
std;
``
int
main(
int
argc,
char
** argv)
{
`` cout <<
"You have entered "
<< argc
`` <<
" arguments:"
<<
"\n"
;
``
`` for
(
int
i = 0; i < argc; ++i)
`` cout << argv[i] <<
"\n"
;
``
`` return
0;
}
in command line if we write
sudo g++ test.cpp
./a.out every thing you want to write
output will be
You have entered 4 arguments:
./a.out
every
thing
you
want
to
write
Sir is it complsory to use command line argument in this question or directly i can use int main()
you can use just simple
int main(){
}
Okay sir thank u know i understood it after reading 2-3 times
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.