What is the difference between two arrays definitions? Are they realized different in memory?
int var = 5;
int (*p4)[2] = new int [var][2]; // first 2d array
int** p5 = new int*[var]; // second 2d array
for(int i = 0; i < var; ++i){
p5[i] = new int[2];
}
Yes, they're very different. The first is really a single array; the second is actually var+1
arrays, potentially scattered all over your RAM. var
arrays hold the data, and one holds pointers to the var
data arrays.
第一个是普通的,完全连续的阵列,第二个也称为锯齿状阵列或lliffe矢量,并且可以例如用于表示三角形结构。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.