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.

Category >> C/C++  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. Stoky on 2014-12-12

    Thanks for this wonderful explanantion

Leave a comment