Why Use Pointers in C?

后端 未结 4 1687
南笙
南笙 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:26

    Another reason: C was designed to build operating systems and lots of low level code that deals with hardware. Every piece of hardware exposes its interface by means of registers, and on nearly all architectures, registers are mapped into the CPU memory space, and they have not to be in the same address always (thanks to jumper settings, PnP, autoconfig, and so on)

    So the OS writer, while writing a driver for instance, needs a way to deal with what seems memory locations, only that they don't refer RAM cells.

    Pointers serve to this purpose by allowing the OS writer to specify what memory location he or she wants to access to.

提交回复
热议问题