Placement of the asterisk in pointer declarations

前端 未结 13 916
闹比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条回答
  •  旧时难觅i
    2020-11-22 05:20

    I would say that the initial convention was to put the star on the pointer name side (right side of the declaration

    • in the c programming language by Dennis M. Ritchie the stars are on the right side of the declaration.

    • by looking at the linux source code at https://github.com/torvalds/linux/blob/master/init/main.c we can see that the star is also on the right side.

    You can follow the same rules, but it's not a big deal if you put stars on the type side. Remember that consistency is important, so always but the star on the same side regardless of which side you have choose.

提交回复
热议问题