yamei2000(临风) 应该可以 只是int a{6}{6}; 应为 int a[6][6] ;
int a[6][6]; int* p=a; for(;p<a+36;p++) { *p=4; } errors: error C2440: '=' : cannot convert from 'int [6][6]' to 'int *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast error C2446: '<' : no conversion from 'int (*)[6]' to 'int *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast error C2040: '<' : 'int *' differs in levels of indirection from 'int (*)[6]' Error executing cl.exe.
int i ; int j ; int a[6][6] ; int* p = (int*)a ; for ( i=0; i<36; ++i ) { *p++ = i ; } for( i=0; i<6; ++i ) { for (j=0; j<6; ++j ) { int k = a[i][j] ; } }
#include "stdafx.h" #include <iostream> using namespace std; int main(int argc, char* argv[]) { cout<<"hello,world!"<<endl; int a[6][6]; int *p=&a[0][0]; for(int k=0;k<36;k++) *(p++)=4; cout<<"end the p"<<endl; for(int i=0;i<6;i++) { for(int j=0;j<6;j++) { int b=a[i][j]; cout<<"start a"<<"["<<i<<"]"<<"["<<j<<"]="<<b<<endl; } } return 0;}
/////////////////////////
int a{6}{6};
int* p=a;
for(;p<a+36;p++)
{
*p=4;
}
//////////////////////////
这不就揭了!
应该可以
只是int a{6}{6}; 应为 int a[6][6] ;
int* p=a;
for(;p<a+36;p++)
{
*p=4;
}
errors:
error C2440: '=' : cannot convert from 'int [6][6]' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2446: '<' : no conversion from 'int (*)[6]' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2040: '<' : 'int *' differs in levels of indirection from 'int (*)[6]'
Error executing cl.exe.
int j ; int a[6][6] ; int* p = (int*)a ; for ( i=0; i<36; ++i )
{
*p++ = i ;
} for( i=0; i<6; ++i )
{
for (j=0; j<6; ++j )
{
int k = a[i][j] ;
}
}
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"hello,world!"<<endl;
int a[6][6];
int *p=&a[0][0];
for(int k=0;k<36;k++)
*(p++)=4;
cout<<"end the p"<<endl;
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
{
int b=a[i][j];
cout<<"start a"<<"["<<i<<"]"<<"["<<j<<"]="<<b<<endl;
}
} return 0;}