Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys ,


I'm receiving following error , when I tried to move address of an array pointer into pointer variable


error C2440: '=' : cannot convert from 'unsigned long (*__w64 )[20]' to 'unsigned long *'


C#
    unsigned long Data[20] ;
    unsigned long *p;


Data[0]=122 ;
   Data[1]=5 ;
   Data[2]=8 ;
   Data[3]=15 ;
   Data[4] =119;
   Data[5] =80 ;
   Data[6] =69 ;
   Data[7] =82 ;
   Data[8] =70 ;
   Data[9] =5 ;
   Data[10]=8 ;
   Data[11]=15 ;
   Data[12]=119 ;
   Data[13]=80 ;
   Data[14]=69;
   Data[15]=82 ;
   Data[16]=70 ;
   Data[17]=5 ;
   Data[18]=13 ;
   Data[19]=15 ;

    p  =  &Data;




Is anything wrong on this ??


Please help....
Posted

1 solution

You should use: p = Data; or p= &Data[0];
 
Share this answer
 
Comments
Baakki 20-Jun-14 2:41am    
unsigned long Data[20] ;
unsigned long *p;

Data[0]=122 ;
Data[1]=5 ;
Data[2]=8 ;
Data[3]=15 ;
Data[4] =119;
Data[5] =80 ;
Data[6] =69 ;
Data[7] =82 ;
Data[8] =70 ;
Data[9] =5 ;
Data[10]=8 ;
Data[11]=15 ;
Data[12]=119 ;
Data[13]=80 ;
Data[14]=69;
Data[15]=82 ;
Data[16]=70 ;
Data[17]=5 ;
Data[18]=13 ;
Data[19]=15 ;


for ( int i=0;i<21;i++)
{

p = &Data[i];
p++;

//m_cdu.SendPointerPageData(p);

}

}

Here p is not storing the array address , it's taking the values .., I donno how , since i am mapping only address...
Raul Iloc 20-Jun-14 3:11am    
You should change your code:

<pre lang="cs">
p = Data; // now "p" is pointing to the first item of the array!
for ( int i=0;i<20;i++)
{
// your other code!

p++; // point to the next item from the array!
}</pre>
Stefan_Lang 20-Jun-14 3:20am    
It should be i<20, and you shouldn't increment the pointer past the end of the array!

Also you need to be aware tha the address of operator has a higher precedence than the subscripting operator, i. e. &Data[i] means (&Data)[i], which is not the same as &(Data[i])!
Stefan_Lang 20-Jun-14 3:24am    
Careful: & has a higher precedence than the subscripting operator, so you should use brackets in your second example.
p = &(Data[i])

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900