简体   繁体   中英

pointer to char confusion

I'm reviewing some topics in the book "The c++ programming language". In the chapter in pointers, Stroustrup have these examples:

int* pi;             // pointer to int
char* ppc;           // pointer to pointer to char
int* ap[15];         // array of 15 pointers to ints
int (*fp)(char*);    // pointer to function taking a char* argument; returns an int
int* f(char*);       // function taking a char* argument; returns a pointer to int

char* ppc;           // this char has only one *, how can this a pointer to pointer to char?

Is this an error in the book or this is entirely correct?

Instead of

char* ppc;           // pointer to pointer to char

it should be

char** ppc;           // pointer to pointer to char

It must be a printing mistake in the book.

You should have ** to get the pointer to a pointer

It should be char** ppc;

Which edition are you reading? It's as follows in my [The.C++.Programming.Language.Special.Edition]:

int* pi; // pointer to int
char** ppc; // pointer to pointer to char
int* ap[15]; // array of 15 pointers to ints
int (*fp) (char *); // pointer to function taking a char* argument; returns an int
int* f(char *); // function taking a char* argument; returns a pointer to int

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM