It's a pointer that points to a pointer that points to a char

As for how it works, work it out. Draw a map of memory and see how it could possibly be layed out and used.

Edited 4 Years Ago by WaltP

think of this like this:

#include <iostream>
using namespace std;

int main(){
    char a='a';
    cout<<"Char a: "<<a<<endl;
    char* p=new char(a);
    cout<<"Char* p(points to a): "<<*p<<endl;
    char** pp=new char*(p);
    cout<<"Char** pp (points to p which points to a): "<<**pp<<endl;
    return (0);
}

Also you can do a 2x2 matrix out of a char**:

#include <iostream>
using namespace std;

#define row 3
#define col 3

char** CreateCharMatrix(){
    char ** matrix;
    matrix=new char*[row];
    for (int i=0;i<row;i++){
        matrix[i]=new char[col];
    }
    return (matrix);
}

void freeMemory(char** matrix){
    for (int i=0;i<row;i++){
        delete [] matrix[i];
    }
    delete [] matrix;
}

int main(){
    char ** matrix;
    matrix=CreateCharMatrix();
    for (int i=0;i<row;i++)
        for (int j=0;j<col;j++)
            matrix[i][j]=char('a'+j);
    for (int i=0;i<row;i++)
        for (int j=0;j<col;j++){
            cout<<matrix[i][j];
            if (j+1==3) cout<<'\n';
        }
    freeMemory(matrix);
    return (0);
}

Don't forget, when you're using memory in a dynamical way, you have to deallocate it manually after you're done.

Edited 4 Years Ago by Lucaci Andrew

thankx i got this..
but i have one more problem....what is a string exactly??
becoz getline(char **,size_t,FILE)
it works as getline(cin,data); //where data is a string i.e. string data;
however somehow i think string is not exactly char **.

This question has already been answered. Start a new discussion instead.