程序一:
#include <iostream>
using namespace std;
int main()
{
int a [8]={212,456, 32, 16,};
cout<<a[0]<<endl;
int *b;
b=a;
cout<<b<<endl;
return 0;
}
输出结果:212
0012FF60
程序二:
#include <iostream>
using namespace std;
int main()
{
int a [3][8]={212,456, 32, 16,};
cout<<a[0][0]<<endl;
cout<<a<<endl;
return 0;
}
输出结果为:
212
0012FF60,说明程序2中的a是一内存地址可赋值给一指针
但下面的程序为什么会出错呢
#include <iostream>
using namespace std;
int main()
{
int a [3][8]={212,456, 32, 16,};
cout<<a[0][0]<<endl;
int *b;
b=a;
cout<<b<<endl;
return 0;
}
错误提示为:
error C2440: '=' : cannot convert from 'int [3][8]' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
程序四:
#include <iostream>
using namespace std;
int main()
{
int a [3][8]={212,456, 32, 16,};
cout<<a[0][0]<<endl;
int *b;
b=a[0];
cout<<b<<endl;
return 0;
}
输出结果:
212
0012FF20
为什么在把b=a改为b=a[0]就有结果输出,而b的值又是谁的内存地址呢;
我想知道二维数组元素如何用指针表示;哪位高手帮一帮我这个初学者.