Reputation: 3
I have read many of the replies to this problem but am not understanding it as it relates to my code so I must ask and hope for clarity.
The program is a magic square verifier for my midterm, and the code runs and outputs properly but I am getting warnings and so I want to clean it up before I submit it. There are actually two bits that give warnings but I am hoping that understanding the first one will help me clean up the second, since I want to understand not just paste an answer.
The code in question:
int ms[COLS][COLS] =
{
{16, 3, 2, 13 },
{ 5, 10, 11, 8 },
{ 9, 6, 7, 12 },
{ 4, 15, 14, 1 }
};
const int* msPtr = ms;
I am trying to set up a constant integer pointer to the first element of my array, something I can pass on to functions so they can use but not modify my array values. I suspect that I am needing to either 'cast' something or have a syntax error here.
The warning is "[Warning] initialization from incompatible pointer type" referring to the "const int* msPtr = ms;" line above.
Thank you for your time.
Upvotes: 0
Views: 97
Reputation: 5287
It should be
const int (* msPtr)[COLS] = ms;
Since ms is 2D array, so require 2D int pointer.
Upvotes: 1