技術(shù)交流QQ群:1027579432星岗,歡迎你的加入填大!
1.數(shù)組作為函數(shù)的參數(shù)傳參時(shí),數(shù)組名會(huì)退化為指針
- 數(shù)組作為函數(shù)的參數(shù)傳參時(shí)俏橘,數(shù)組名會(huì)退化為指針允华,數(shù)值傳參時(shí),需要把數(shù)值的長度一起傳過去寥掐,另外例获,sizeof()運(yùn)算符包含字符串的哨兵'/0',而strlen()函數(shù)不包含哨兵,具體參見下面的實(shí)例:
#include <iostream>
using namespace std;
void example(char acWelCome[]){
cout << "sizeof(acWelCome) in example = " << sizeof(acWelCome) << endl;
}
int main(){
char acWelCome[] = "Welcome to HuaWei Test";
example(acWelCome);
cout << "sizeof(acWelCome) in main = " << sizeof(acWelCome) << endl;
return 0;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者