私のコンパイラは g++ 4.7.3 です
long i = 2222;
const long& lref = i;
const int& iref = i;
printf("i=%p lref=%p iref=%p \n", &i , &lref, &iref);
結果は
i=0xbfd78760 lref=0xbfd78760 iref=0xbfd78764
のアドレスiref
がより高い理由i
私はそれがちょうどこのようになると思いconst int&
ますlong
:
int temp = i
const int& iref = temp;
================================================== ========
コード2
ただし、次のようなコードの場合
long i = 2222;
const long& lref = i;
const int& iref = i;
int a = 10;
int b = 10;
printf("i=%p lref=%p iref=%p a=%p b=%p\n", &i , &lref, &iref, &a, &b);
結果は
i=0xbfade768 lref=0xbfade768 iref=0xbfade774 a=0xbfade76c b=0xbfade770
a
andのアドレスがスタックb
よりも低いのはなぜですか?iref
================================================== ========
コード3
コードが好きなとき
long i = 2222;
const long& lref = i;
const int& iref = i;
printf("i=%p lref=%p iref=%p \n", &i , &lref, &iref);
結果は
i=0xbfbe3f84 lref=0xbfbe3f84 iref=0xbfbe3f83
のタイプが の場合、のアドレスが より小さいのiref
はなぜですか?char
iref
i
誰かが私の理由を教えてくれませんか、ありがとう!