Where are addresses of pointers stored in C?

后端 未结 5 1877
慢半拍i
慢半拍i 2021-02-10 10:01

I\'m learning C and currently learn about pointers. I understand the principle of storing the address of a byte in memory as a variable, which makes it possible to get the byte

5条回答
  •  遇见更好的自我
    2021-02-10 10:47

    Let's say the value of a pointer (the address of a byte in memory) is stored somewhere in memory

    The address of a byte that you allocated, say like this

    char ch = 'a';
    

    is referenced by the compiler in the symbol table with the right offset. At run time, the instructions generated by the compiler will use this offset for moving it to from the primary memory to a register for some operation on it.

    A pointer, in the sense you're asking, is not stored anywhere, it's just a type when you refer to a variable's address, unless you explicitly create a pointer variable to store it like this

    &ch;             // address of ch not stored anywhere
    char *p = &ch;   // now the address of ch is stored in p
    

    Thus there's no recursion concept here.

提交回复
热议问题