您的位置:首页 > 编程语言 > C语言/C++

c++数组宽度计算的sizeof关于指针设想

2015-09-03 15:27 417 查看

1.函数传递不了sizeof 要通过手动传递n</h3>

void __count(int cptr[]){
cout << sizeof(cptr) / sizeof(cptr[0]) << endl;
}


2.指针不课初始化为数组,char*也只能初始化"串"

int main(){
int Array[5] = { 255, 423, 74, 11, 88 };

int *iptr = Array;
cout << iptr[3]<<endl;//11
cout << sizeof(Array) / sizeof(Array[0])<<endl;//5
cout << sizeof(iptr) / sizeof(iptr[0]) << endl;//1

__count(Array);//1

char*str = "hello fucking hard!";
cout << str << endl
<< str[19] << endl;

//char *ch = { 'h', 'e', 'l','\0'};//错误
//int *iptr2 = { 255, 423, 74, 11, 88 };//错误,初始值设置过多
return getchar();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: