When I tried to find where Pointers store themselves, their addresses, and address values. The same with References.
Example 1:
int a = 1;
int *b = new int{ 5 };
int &c = a;
I know that a
with 1
are stored on the stack, but are they in the same memory block?
I have information, that *b
with a reference to value 5
are stored on the stack, but the value 5
is stored in the heap.
I heard that &c
with a reference to a isn't stored in the memory because it's an alias. But other people said another thing, so the same question as for *b
, how are they all stored in memory?
I think it would be much more interesting to know deeper about this topic.
Example 2:
void Func1(int a)
{
// code
}
void Func2(int *b)
{
// code
}
void Func3(int &c)
{
// code
}
I know that argument a
is copied to the function memory on the stack.
I have information that *b
is copied to the function memory on the stack, but copied only *b
, not its reference to the value which is stored in the heap.
I heard that &c
don't copy because the function uses the value located on the heap directly through this reference.
How do examples 1 and 2 actually work in memory?
I tried to find answers to this question using Google, Bing AI and ChatGPT, but answers vary.
My compiler is x64 MSVC 14.35.32215