如下的程序,我要存储9个字符串,下面的方式都可以实现,但是发现采用指针数组时系统还额外占用了36字节RAM,这么看来直接采用字符数组的方式更好了?
单从占用空间大小来看的话,大家讨论下我理解的对不?
- const char Planets[][8]= {"mercury","venus","earth","mars","jupiter","saturn","uranus","neptune","pluto"};
- const char *pPlanets[] = {"mercury","venus","earth","mars","jupiter","saturn","uranus","neptune","pluto"};
- int sizea=0;
- int sizeb=0;
- int main(void)
- {
- sizea=sizeof(Planets);
- sizeb=sizeof(pPlanets);
- sizea=Planets[0][0];
- sizeb=pPlanets[1][0];
-
- while(1);
- }
复制代码
仿真图片如下:
2019-03-07_124249.png (133.41 KB, 下载次数: 0)
下载附件
2019-3-7 13:31 上传
一周热门 更多>