C++数组
#include <iostream.h>
void main()
{
int array[4] = {10,20,30,40};
cout<<"array is "<< array<<"\n";
cout<<"is't content is "<< *(array)<<"\n";
cout<<"array[0] is "<< &(array[0])<<"\n";
cout<<"is't content is "<<*&(array[0])<<"\n";
/* 输入结果如下
array is 0x0012FF38
is't content is 10
array[0] is 0x0012FF38
is't content is 10
*/
}
结论:数组名称即代表它的第0个元素的地址。
可以用如下方法获取数组中元素地址:
(1)&array[i] (2)array + i
可以用如下方法来获取数组中元素内容:
(1)array[i] (2)*(array + i)