変数、メモリ


int main() {
	int a = 0;
    int b = 3;
    int c = a + b;
    int d = 2.5;
    
    return 0;
}

c++では、変数名にどの数字があるかを覚える必要はありません.
スタックメモリ領域のtop位置から、いくつ目に何の数字があるかを覚えます.
#include <iostream>
using namespace std;
int main() {
	int a = 0;
    int b = 3;
    int c = a + b;
    int d = 2.5;
    
    cout << (long)&a << endl;
    cout << (long)&b << endl;
    cout << (long)&c << endl;
    cout << (long)&d << endl;
    
    return 0;
}

a,b,cは4バイト
dは8バイトフォーマットであり、typeごとに割り当てられるサイズが異なる.
メモリ割り当てはコンパイラによって異なりますが、UNIXベースのgcc clangコンパイラでは1つのプロセスしか実行されません.

上の図のように、変数を入力するたびにメモリアドレスが減少する方向に入ります.