Placement of the asterisk in pointer declarations

前端 未结 13 1161
闹比i
闹比i 2020-11-22 04:36

I\'ve recently decided that I just have to finally learn C/C++, and there is one thing I do not really understand about pointers or more precisely, their definition.

13条回答
  •  温柔的废话
    2020-11-22 05:27

    The pointer is a modifier to the type. It's best to read them right to left in order to better understand how the asterisk modifies the type. 'int *' can be read as "pointer to int'. In multiple declarations you must specify that each variable is a pointer or it will be created as a standard variable.

    1,2 and 3) Test is of type (int *). Whitespace doesn't matter.

    4,5 and 6) Test is of type (int *). Test2 is of type int. Again whitespace is inconsequential.

提交回复
热议问题