What is the point of pointers?

后端 未结 12 1511
梦谈多话
梦谈多话 2021-02-01 18:49

What is the point of pointers in C++ when I can just declare variables? When is it appropriate to use them?

12条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 19:38

    Pointers are most useful when dealing with data structures whose size and shape are not known at compile-time (think lists, trees, graphs, arrays, strings, ...).

    Edit

    These related answers might also help (the top answer in the second link is definitely worth a look):

    In C++ I Cannot Grasp Pointers and Classes

    What are the barriers to understanding pointers and what can be done to overcome them?

提交回复
热议问题