address of register variable in C and C++

前端 未结 8 1893
野趣味
野趣味 2021-01-06 03:00

I know the concept of register variable and it\'s use cases but there are few questions in my mind based on what I have tried.

  1. I cannot access the address

8条回答
  •  伪装坚强ぢ
    2021-01-06 03:32

    The basic answer is that, on most architectures, general purpose registers do not have memory addresses. In general, a pointer is simply a (virtual) memory address of the memory location containing the object. This is done of efficiency.

    It would be possible to extend the concept of a pointer to point to memory or register. However, doing so would decrease program speed as the code to dereference a pointer would need to check what type of location is being pointer to.

提交回复
热议问题