!!The question is a little long, so I divided it into 4 parts, so that the reader would not be distracted!! I got a piece of information recently, that the name of the array in C/C++ is a pointer to the first element in the array, and that was from an AI (Chat GPT 3.5 and 4) and my tutor at university. And when I was looking at the memory locations for each of the pointer (the name of the array) and the first element and the address stored in the pointer, I found that they are all equal.
#include<iostream>
using namespace std;
int main (){
int arr[3]{1,2,3};
cout << &(arr) <<" "<<&arr[0] <<" "<< arr <<endl;
return 0;
}
/*
Output:
0x69fee0 0x69fee0 0x69fee0
*/
And here lies the first point or problem, how is the address of the pointer equal to the address that the pointer stores, as if we say a pointer points to itself and this will become an endless loop.
When I searched for the answer to this question, I found some specialists saying that the name of the matrix is not an indicator at all. Here is the second point.
When I searched more and more, I found an answer that says: It is true that the pointer has the same address followed by its value, but this does not mean that the pointer is located in the same memory space, He said that the bit space varies, which is inferred by the following program:
#include<iostream>
using namespace std;
int main (){
int arr[3]{1,2,3};
cout << &(arr) <<" "<<&arr[0] <<" "<< arr <<endl;
cout << &(arr)+1 <<" "<<&arr[0]+1<<" "<< arr+1<<endl;
cout << &(arr)+2 <<" "<<&arr[0]+2<<" "<< arr+2<<endl;
cout << &(arr)+3 <<" "<<&arr[0]+3<<" "<< arr+3<<endl;
cout << sizeof(arr) <<" "<<sizeof(&arr[0])<<" "<< sizeof(&arr)<<endl;
return 0;
}ٍ
/*
Output:
0x69fee0 0x69fee0 0x69fee0
0x69feec 0x69fee4 0x69fee4
0x69fef8 0x69fee8 0x69fee8
0x69ff04 0x69feec 0x69feec
12 4 4
*/
And This was the third point.
Regarding the fourth and most important point: It is that I deduced the shape of the memory through the outputs of the previous program, as we do in the science of logical circuits deducing the circuit through the outputs. And I want you to see if the drawing (unscientific, but to bring the idea closer) is correct in its general idea, and any comments on it are very important to me, because I am really interested in how the memory will look in the event that the name of the matrix is a pointer. Finally, when you see the drawing, there is an important question: Is the memory in the RAM really divided into two halves, as shown in the drawing? Which half of the pointer and half of the matrix, and if that is true, what is the mechanism?
diagram :