开发者

what is this in C++?

int* i;

int * i;

int **i;

i know

int *i;
开发者_如何学运维represent pointer variable


Spacing doesn't make any difference, so the first two are identical.

int** i;

Is a pointer to a pointer to an int.

For example, if i held a pointer value, then that would mean that in the memory starting at that address there was another pointer, this time directly to an int, and if you followed that address then you'd find an actual int number value.

int an_int = 3;
int* p = &an_int;
int** pp = &p;

This forms a chain ala...

int** pp = &p ------> int* p = &an_int ------> int an_int = 3


The first two are exactly the same.

int **i implies, i can hold the address of a pointer. That is, a pointer to a pointer.


Whitespace is insignificant in this case. int * i means the same as int* i and int *i. All are pointers to an integer. int ** i is different, this is a pointer to a pointer to an integer.


All of these are the same and are a pointer to an integer:

int* i;
int * i;
int *i;

This is a pointer to a pointer to an integer:

int **i;


int* i;

a pointer to an int. potentially used as a 1d array

int * i;

also a pointer to an int

int **i;

a pointer to a pointer to an int. potentially used as a 2d array


int *i;, int* i; or int * i;

These are all identical because spaces do not make any difference. It is used to hold the address of an integer. Usually used in a dynamic, one dimensional integer array.

Similarly,

int **i;, int** i; or int ** i;

Are all identical because spaces do not make any difference. It is used to hold the address of a pointer to an integer. Usually used in dynamic, two dimensional integer array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜