linag wei,
wo ji ben kan guo le suo you de tie zhi le.
一、
int*p;
int arr[10][10];
p=arr; // pay attention here, here is wrong, why? because the type is not same, p is type from int * and arr is type from
2 dimensional array, so they are not same type.
//改成p=&arr[0][0]; // but here is right, why? let us take a look, arr[0][0] is an integer invalue, and with & will get the address of this value, so &arr[0][0] is an address of an integer value, and p is pointer to integer so they are same type.
二、
int *p[10];
for(int i=0;i<10;i++)
p[i]=new int[10];
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
p[j][k]=arr[j][k];
Method 1 is not right, because one dimension array is not same as 2 dimensional array. In Programming you can use one dimensional array to work with 2 dimensional array, but not encourage.
Method 2 is total right.
first look hier int * p[10]; this declartion tell the compiler this is an pointer array and in type integer, so the compiler will allocate 40Byte for this pointer array. pay attention here, after declartion, the space is already allocated, that mean, this 40 Byte is there.
now the program use a for loop and p[i] = new int[10]; here compiler will allocate 40Byte again for every p[i], and after allocation the address will be assigned to p[i]. Let's say something concrrect, first time the allocation is not dynamica, it is static, it is just like int a; here a is also has a place to receive his value. And here int * p[10]; the place is also static, suppose the first address is 2000, then the second is 2004 and so on. Now after p[i]=new int[10]; for example p[0] get the first address for this allocation is 3000, then this 3000 will be saved in the space which has the address 2000, and the other is same.
and this last two for loop is just for initialization.
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
p[j][k]=arr[j][k];
so it is correct.
Now to some other subject,
穆扬. you have said something about type convertion.
for instance:
int * p = new int;
double * pd = new double;
pd = (double *)p; // it is correct, why? because, I have casted the type to the same type.
pd = p; // here is of course not right, why? because they are not tpye.
I think, my personal meaning, 穆扬 is a little more than normal discuss. wfpb has well done. So I think 穆扬 you should change your attitute. Discussion is just discussion, every one can say your meaning. Even your meaning is wrong. It is also ok, the important thing is, after discussion, you should learned something, and you need not care, whether some one else also learned something, you are not teacher, I am also not, So it is not semeter exam. You need just look at yourself, you need just take care of yourself.
And, and this is also but, you can, and you also should keep your meaning, keep your mind, when you are not sure, whether the other ones are right, or when you still not understand, then please ask the question, till you get the meaning. That is learning.
Through this discussion, I hope 穆扬 and wfpb never keep attack to each other. I think, you are both good boy. Why not friend? I hope so.
C is a subset for C++, that is right, but it doesn't mean, C++ is just C, or otherwise, C is just C++. No, these 2 things has very different philosophy. My personal meaning, c++ is a language for freedom. Why freedom? not understand? Here freedom does mean, someone can use C++ implement his thought, his logic. You should know, the human being is different, they have total different thought model. That mean, the aspect of viewing of a problem can be huge different. And with c++ you can implement your thought without any restriction. Here I have not spoken anything about effiencient. First the freedom for thought should be protected, this is very important, because the development in multidimension is better than its in one dimension. Only so, the technic will be improved in a compromise wise.
For a c++ programmer, he look the the world is real, that mean, all are object, the real world is just a set of Objects, and the system is some objects with their relation. So solving a problem is just the simulation der real world. And meanwhile, c programmer see the solving of a program is a chain of the solving of subproblem. So you see, the aspect is different.
Words till now.
To technic problem, anyone can still make discussion continue. And I will also join us.