您的位置:首页 > 其它

作为参数的数组实际上是指针

2014-03-14 23:41 281 查看
#include "stdafx.h"
#include <iostream>
using namespace std;

void f(int b[])
{
	cout << "======== f ========" << endl;
	cout << "b == " << b <<endl;
	/*
		无法再另一个函数中自动的决定一个数组编译时的大小
	*/
	cout << "sizeof b == " << sizeof b << endl;
	cout << "======== f ========" << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int a[] = {1,2,3,4};
	f(a);
	
	/*
		输出:
		======== f ========
		b == 0018FF1C
		sizeof b == 4
		======== f ========
	*/

	system("pause");
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: