精華區beta EE_DSnP 關於我們 聯絡資訊
int main() { double a[10]; double* b = new double; double* c = new double[10]; double** d = new double*[10]; cout << "a = " << a << endl; cout << "a+1 = " << a+1 << endl; cout << "b = " << b << endl; cout << "b+1 = " << b+1 << endl; cout << "c = " << c << endl; cout << "c+1 = " << c+1 << endl; cout << "d = " << d << endl; cout << "d+1 = " << d+1 << endl; } Some of what I said in the class were wrong --- the value of “c+1” is the address of “c” plus the size of the object (i.e. 8 Bytes), NOT the size of a pointer (i.e. 4 Bytes). So for variables “a”, “b”, and “c”, their “+1” addresses will be 8 Bytes more. For “d”, it’s 4 Byte. A sample output for the above code is: a = 0xfee6ef20 a+1 = 0xfee6ef28 b = 0x97a7008 b+1 = 0x97a7010 c = 0x97a7018 c+1 = 0x97a7020 d = 0x97a7070 d+1 = 0x97a7074 關於上面這個: 1. b和c不都是double pointer, 按照老師說的, b+1 c+1的效果不是應該是 b+1=0x97a7016(產生的object是double array? double的object是8 bytes) c+1=0x97a7026 (理由也是同上) 2. 0xfee6ef20 這是位置我知道, 可是他有代表什麼意義?例如:編碼... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.208.42
alleternal:double** d = new double*[10]; 這個d是什麼樣的data 11/06 19:44
alleternal:type? 後面new出來的又是什麼東西?產生在哪裡? 11/06 19:46
admitted:ㄟ這個是16進位的表示法,不是十進位 11/06 20:37
ric2k1: 推~~~ 是16進位 11/06 22:45
ric2k1:0xfee6ef20 是 stack memory 中 local object 的 address 11/06 22:46