Why Use Pointers in C?

后端 未结 4 1612
南笙
南笙 2020-12-29 07:01

I\'m still wondering why in C you can\'t simply set something to be another thing using plain variables. A variable itself is a pointer to data, is it not? So why make poi

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 07:09

    A variable itself is a pointer to data

    No, it is not. A variable represents an object, an lvalue. The concept of lvalue is fundamentally different from the concept of a pointer. You seem to be mixing the two.

    In C it is not possible to "rebind" an lvalue to make it "point" to a different location in memory. The binding between lvalues and their memory locations is determined and fixed at compile time. It is not always 100% specific (e.g. absolute location of a local variable is not known at compile time), but it is sufficiently specific to make it non-user-adjustable at run time.

    The whole idea of a pointer is that its value is generally determined at run time and can be made to point to different memory locations at run time.

提交回复
热议问题