What is the point of pointers?

后端 未结 12 1435
梦谈多话
梦谈多话 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:46

    Apart from efficiency and flexibility.The main point of pointers in C/C++ is that is how the hardware works, you could not wite a device driver, memory manager or efficient cache without using pointers somewhere along the line.

    One of the main design goals for the first C compiler was to be a "portable assembly language" and to be able to do in a higher level language anything you could do with traditional assembly/machine code. This means being able to manipulate addresses directly - which is the point of pointers.

    However following the KISS principle dont use pointers unless they really are making things simpler.

提交回复
热议问题