i am writing in c, using Visual c++.
The compiler gives me the errors with the code below:
#define SIZE 3;
int myMatrix[SIZE][SIZE];
void funcMatrix(int M[SIZE][SIZE]);
The errors i get:
error C2143: syntax error : missing ']' before ';'
error C2059: syntax error : ']'
Ive tried declaring the constant differently, inside main and outside. It still doesn't work. Would really appreciate it if someone can help me out...
You should use #define SIZE 3.
Preprocessor works as a raw string substitution, so with #define SIZE 3; your SIZE is replaced with 3; and you get:
int myMatrix[3;][3;];
void funcMatrix(int M[3;][3;]);
as a final result, hence the errors. This is a common error, then you get used to place ; at the end of C expression. However the preprocessor #define-s are not C code actually, but a simple (or not so simple) string processing operation which occurs before compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With