I wondered how char sequence(string) arranged in RAM, so make below testing with c++. The compiler environment is 64bit system, cygwin on windows10.
#include <iostream>
using namespace std;
int main() {
char* c1 = "01";
cout << "string to print:" << endl;
cout << c1 << endl;
cout << "the address in stack of the pointer:" << endl;
cout << &c1 << endl;
cout << "the address in heap for the first letter in the string:" << endl;
cout << (void*)c1 << endl;
cout << "the address in heap for the second letter in the string:" << endl;
cout << (void*)(++c1) << endl;
}
output is:
string to print:
01
the address in stack of the pointer:
0xffffcc28
the address in heap for the first letter in the string:
0x100403001
the address in heap for the second letter in the string:
0x100403002
I recognize that the address of char '0' and '1' just offset 1byte. So is that mean the two chars just arrange one by one in one ram unit? As below illustration?
/*
* 64bit ram
* |-------------------------64bits--------------------------------|
* stack | |
*
* heap | 8bits | 8bits | 8bits | 8bits | 8bits | 8bits | '1' | '0' |
*/