Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error : missing ']' before ';' Array declaration error in C

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...

like image 277
kype Avatar asked Sep 30 '26 04:09

kype


1 Answers

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.

like image 134
Petr Abdulin Avatar answered Oct 01 '26 18:10

Petr Abdulin