Item08. Points to Pointers

xiaoxiao2021-03-05  21

Item08. Pointers to Pointers

Pointer to pointers (multi-level pointers) and pointers are also different from the pointers ----------------------------------------------------------------------------------------------------------------------- ------------- 1, change the address of the pointer points to

Void Scanto (const char ** p, char c) {while (** p && ** p! = c) * p;} char s [] = "Hello, World!"; const char * cp = s ScanTo (& CP, ','); // Pointing ","

2, priority use of references void scanto (const char * & p, char c) {while (* p && * p! = C) p;

3, the difference between pointer and multi-level pointer 1) Pointer can be used in polymorphism, and multi-level pointers cannot

Circle * c = new circle; shape * s = c; // correct ... circle ** cc = & c; shape ** ss = cc; // error!

2) After adding const stiff, the non-pointer constant can assign a value to the pointer constant, but cannot assign a value to the multi-level pointer.

Char * S1 = 0; const char * s2 = S1; // correct ... char * a [max]; // aka char ** const char ** ps = a; // Error!

转载请注明原文地址:https://www.9cbs.com/read-37546.html

New Post(0)