pointer
is a pointer. It is the size of a pointer, which is 4 bytes on your system.
*pointer
is also a pointer. sizeof(*pointer)
will also be 4.
**pointer
is a char. sizeof(**pointer)
will be 1. Note that **pointer is a char because it is defined as char**
. The size of the array new`ed nevers enters into this.
Note that sizeof
is a compiler operator. It is rendered to a constant at compile time. Anything that could be changed at runtime (like the size of a new'ed array) cannnot be determined using sizeof
.
Note 2: If you had defined that as:
char* array[1];
char** pointer = array;
Now pointer
has essencially the same value as before, but now you can say:
int arraySize = sizeof(array); // size of total space of array
int arrayLen = sizeof(array)/sizeof(array[0]); // number of element == 1 here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…