What is the point of pointers?

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

    I had the exact same question when I was learning pointers, they just didn't seem important, but as you progress, you find out they are some times very useful.

    Pointers are used often in programming situations. For example, when you reference an array by name, such as array[i] = 3; The compiler is doing some fancy math that ends up turning that code into

    (address of array) + (sizeof(array elements) * i) = 3;

    They also make trees, linked-lists and other data structures possible, which you will find out as you learn more.

提交回复
热议问题