c++數組寬度計算的sizeof關於指針設想

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();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章