Two-weight pointer
Example 1:
int **ptr1 = NULL; cout<< "Situation one ptr1 = =" <<ptr1<<endl; cout<< "Situation one *ptr1 = =" <<*ptr1<<endl; cout<< "situation one **ptr1 = =" <<**ptr1<<endl; Output: 0 illegal illegal
1) Three-province pointers: The type of pointer ptr1 is int * *, to the type int*, specified as empty
2) *PTR1 is the point that ptr points to, that is, the null point, illegal
3) **PTR1 is the pointing point that ptr points to, that is, pointing to an empty point, illegal
Example 2:
int * P1 = (int *) malloc (sizeof (int)); int **ptr2 = &p1; cout<< "Situation two ptr2 = =" <<ptr2<<endl; cout<< "Situation two *ptr2 = =" <<*ptr2<<endl; cout<< "situation two **ptr2 = =" <<**ptr2<<endl;
#include <bits/stdc++.h>using namespace Std;int main () { int * p1 = (int *) malloc (sizeof (int)); int **ptr2 = &p1; cout<< "Situation two P1 = =" <<p1<<endl; cout<< "Situation two *p1 = =" <<*p1<<endl; cout<< "Situation two &p1 = =" <<&p1<<endl; cout<< "Situation two ptr2 = =" <<ptr2<<endl; cout<< "Situation two *ptr2 = =" <<*ptr2<<endl; cout<< "situation two **ptr2 = =" <<**PTR2<<ENDL;}
1) Three-province pointer: the type of pointer p is int *, which points to the type int, initialized to not specify its point
2) Three-province pointers: The type of pointer ptr2 is int * *, the point of type int*, the address of the pointer P (note that at this point ptr2 and &p type are int**, you can assign values)
3) *PTR2 is the ptr2 point, that is, &p1 point, for the P1
4) **PTR2 is the point of the ptr2 point, that is, *ptr2 Point, for *p1
5) The pointer is the address, so as &p1 points to P1
Example 3:
int * P2 = (int *) malloc (sizeof (int)); int num = 6; P2 = # int **PTR3 = &p2;
#include <bits/stdc++.h>using namespace Std;int main () { int * p2 = (int *) malloc (sizeof (int)); int num = 6; cout<< "situation three P2 = =" <<p2<<endl; P2 = # int **PTR3 = &p2; cout<< "situation three P2 = =" <<p2<<endl; cout<< "situation three *p2 = =" <<*p2<<endl; cout<< "situation three &p2 = =" <<&p2<<endl; cout<< "situation three &num = =" <<&num<<endl; cout<< "situation three PTR3 = =" <<ptr3<<endl; cout<< "situation three *PTR3 = =" <<*ptr3<<endl;
1) Three-province pointers: The type of the pointer p2 is int *, the type of int, the initialization is not pointed, and the pointer is &num (note that at this point P2 and &num type are int*, you can assign a value)
2) Three-province pointers: The type of pointer ptr3 is int * *, the point of type int*, the address of the pointer P2 (note that at this point ptr2 and &p2 type are int**, you can assign a value)
3) *PTR3 is the PTR3 point, that is, &p2 point, for the P2
4) **PTR3 is the point of the Ptr3 point, that is, *ptr3 Point, for *p2
5) The pointer is the address, so as &num points to num, as &p2 points to P2Spit Spit Spit Spit Spit
: Write blog is tired ah ah ah ah, blog Park Why so bad use, is I open the way wrong????
C Language Pointer usage details (iii) Double pointer