const char *pointerStr[]=
{
"BEST123, ", // 0x00
"Best2233, ", // 0x01
"ABCDEFGH, ", // 0x02
"123456, ", // 0x03
"helloworld, " // 0x04
};
typedef struct
{
char value;
char name[40];
}StrInfo;
typedef struct
{
int regMax;
StrInfo info[60];
} structNew;
void main()
{
int i;
structNew pret;
for (i=0;i<5;i++)
{
printf("PointerStr size of %dth %d \n",i,sizeof(pointerStr[i]));
printf("pret size of %dth %d \n",i,sizeof(pret.info[i].name));
}
}
的上述程序產生的sizeof如何工作?存儲器映射可變長度字符串數組
PointerStr size of 0th 4
pret size of 0th 40
PointerStr size of 1th 4
pret size of 1th 40
PointerStr size of 2th 4
pret size of 2th 40
PointerStr size of 3th 4
pret size of 3th 40
PointerStr size of 4th 4
pret size of 4th 40
如果我想知道每一個的大小和PointerStr每個字符串再怎麼找呢,結果呢?是否有可能只使用strlen?我們有其他方法嗎?這個變長數組如何存儲在內存中? 結果是因爲pointerStr是指針變量,其大小始終爲4.請糾正我,如果我錯了。
對於普通的以0結尾的字符串,就像'pointerStr ',那麼'strlen'就是你應該使用的。 –
代碼中沒有可變長度數組。所有這些都是在編譯時固定的。 –