Double star after type and before variable

What does ** mean in the following code?

char **argv;

It declares argv as a pointer that points to a char pointer. It is equivalent to the following code.

char *argv[];

Here is a good example.

#include <unistd.h>
#include <iostream>
 
using namespace std;
int test(int argc, char **argv) {
 
        // Start at 1 to skip the program name                                                                                                                                                                                              
        for (int i = 1; i < argc; ++i) {
                for (int j = 0; argv[i][j] != '\0'; ++j) {                                                                                                                                                                                 
                        cout << *(argv + i) << '\n'; // this and next line are the same                                                                                                                                                                
                        cout << argv[i] << '\n';
                        cout << *(*(argv + i) + j) << '\n';
                }
        }
 
}
 
int main(int argc, char **argv){
 
        //how to pass pointers                                                                                                                                                                                                              
        cout << argc << "parameters"<<endl;
        test(argc, argv);
 
}

An interesting question is how to initialize “str” declared in “char **str”?
A diagram is worth thousand words.
argv

1 thought on “Double star after type and before variable”

Leave a Comment