int a[6][6];int **p; p=(int **)a; 
for(int i=0;i<6;i++)
   for(int j=0;j<6;j++)
//*(*(p+i)+j)=i;
p[i][j]=4;
能否通过指针对数组元素赋值,请指教

解决方案 »

  1.   

    干嘛要怎么麻烦呢?
    /////////////////////////
    int a{6}{6};
    int* p=a;
    for(;p<a+36;p++)
    {
         *p=4;
    }
    //////////////////////////
    这不就揭了!
      

  2.   

    yamei2000(临风) 
    应该可以
    只是int a{6}{6}; 应为 int a[6][6] ;
      

  3.   

    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.
      

  4.   

    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] ;
    }
    }
      

  5.   

    #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;}