先上代码:
float gcode[10][2]={ {0.00,0.00}, {100.00,0.00}, {100.00,50.00}, {0.00, 50.00}, {0.00,100.00}, {100.00,100.00}, {100,150.00}, {0.00,150}, {0.00,200.00}, {100.00,200.00} };void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.PRintln("hello world");}void loop (){ Serial.println(sizeof(gcode)); Serial.println(sizeof(gcode[0])); Serial.println(sizeof(gcode[0][0])); Serial.println("ok"); while(1);}以下是运行结果:hello world8084ok
解析:
sizeof(gcode),gcode指向整个二维数组,所以sizeof(gcode)求的是二维数组的字节数,10*8=80;
sizeof(gcode[0]),gcode[0]指向二维数组第一行,第一行共有4*2=8;
sizeof(gcode[0][0]),gcode[0][0]指向二维数组第一个元素,float 为4字节。
新闻热点
疑难解答