二维数组的初始化(二维数组的赋值)
二维数组的初始化必须在声明的时候进行。否则会报错。
比如,你应该在声明它的时候就立即赋值:
unsigned char bitmap[16][17]={ {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0}, {255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0}, {0,0,255,255,255,0,0,0,0,255,255,255,255,255,255,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0}, {0,0,0,255,255,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0}, {255,255,255,255,255,0,0,0,0,0,255,255,255,255,0,0,0}};
如果改成这样就会报错:
unsigned char bitmap[16][17];
bitmap[16][17]={ {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0}, {255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0}, {0,0,255,255,255,0,0,0,0,255,255,255,255,255,255,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0}, {0,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0}, {0,0,0,255,255,0,0,0,0,0,255,255,255,255,0,0,0}, {0,0,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0}, {255,255,255,255,255,0,0,0,0,0,255,255,255,255,0,0,0}};
报错:
1>d:vs_promark_regionspan_cclmain.cpp(23) : error C2059: syntax error : { 1>d:vs_promark_regionspan_cclmain.cpp(23) : error C2143: syntax error : missing ; before { 1>d:vs_promark_regionspan_cclmain.cpp(23) : error C2143: syntax error : missing ; before }
而且你很难找出出错的原因。