Address of a variable using pointer
c, pointers
Solution
The address of `addr` isn't "stored" anywhere explicitly, it just is. If you were to declare a second variable and use it to store that address, then sure it takes space:
int **addr2 = &addr;
You can think of the memory as a series of boxes. Assuming 4-byte `int` and pointers, and little-endian byte order, your scenario might look like:
+----------+--+--+--+--+
| Address |Data bytes |
+----------+--+--+--+--+
|0x00000000|64|00|00|00|
+----------+--+--+--+--+
|0x00000004|00|00|00|00|
+----------+--+--+--+--+
The address is shown on the left, the bytes contained at that location on the right. You can see the value `100` stored in the first four bytes (100 decimal is 0x64 in hex). The second 4-byte location holds the value 0x00000000, which is the address of `x`. The address 0x00000004 is not stored anywhere.
Now if we add a second pointer, we'd use more memory:
+----------+--+--+--+--+
|0x00000008|04|00|00|00|
+----------+--+--+--+--+
That would be the memory used to represent the `addr2` pointer, and you can see that it contains the address of `addr`, i.e. 0x00000004.
Dereferencing `addr2` with the expression `*addr2` would yield the value at address 0x00000004, i.e. 0x00000000 with the type `int *`. De-referencing that once more yields the `int` at that address, i.e. 0x00000064.
Since this memory layout is chosen by the compiler, it "knows" the addresses involved, and can just substitute so that when code references `addr2`, it generates instructions that manipulate address 0x00000008, and so on. In real code this would probably all happen on the stack, but the principle is the same.
Final note: do heed @Phil Perry's advice; the above simplifies and makes ocncrete a lot of things that are meant to be somewhat abstract. This is how it really does work on many current-day architectures, but many of the things mentioned are not guaranteed by C so you cannot really depend on them to always hold true. I meant the above as an illustration to (hopefully) make the concepts slighly less vague.
Problem
Consider the following code in C ``` int x=100; int*addr=&x; ``` I know that addr will store the address of x.A question that keeps popping in my mind is that the addr pointer will have its own address and that can again be accessed using ampersand operator and that too will be stored somewhere,so we have here infinite recursion on addresses so where does this end?