即時通訊嘗試獲取sizeof char數組變量在一個不同的函數初始化,但不能得到正確的sizeof。請參閱下面的代碼找到sizeof字符數組C++
int foo(uint8 *buffer){
cout <<"sizeof: "<< sizeof(buffer) <<endl;
}
int main()
{
uint8 txbuffer[13]={0};
uint8 uibuffer[4] = "abc";
uint8 rxbuffer[4] = "def";
uint8 l[2]="g";
int index = 1;
foo(txbuffer);
cout <<"sizeof after foo(): " <<sizeof(txbuffer) <<endl;
return 0;
}
輸出爲:
sizeof: 4
sizeof after foo(): 13
所需的輸出是:
sizeof: 13
sizeof after foo(): 13
+1。正是我在想什麼。 –
@Marlon即時通訊新的模板在C++中,所以我應該如何調用函數foo ?,一個例子將不勝感激。 –
@ user945511我編輯了我的答案。 – Marlon