变量在栈中的内存分配 先入栈放在高地址

//============================================================================
// Name        : Testcpp.cpp
// Author      : Lucas
// Version     :
// Copyright   : @Lucas
// Description : 先入栈的在高地址。
//============================================================================

#include <iostream>
using namespace std;

void fun(int x = 1, int y = 2)
{
	cout << &x << endl;
	cout << &y << endl;
}

int main()
{
	int a = 1;
	int b = 2;

	cout << &a << endl;	//0x22ff4c

	cout << &b << endl;     //0x22ff48

	return 0;
}

 

 

//============================================================================
// Name        : Testcpp.cpp
// Author      : Lucas
// Version     :
// Copyright   : @Lucas
// Description : 数组在内存中的存放地址。
//============================================================================

#include <iostream>
using namespace std;

int main()
{
	int a[3] = {1, 2, 3};
	int b[3] = {4, 5, 6};

	//a放在高地址,b放在低地址;但在a中,a[0]放在地地址,a[1]放在高地址。
	cout << &a[0] << endl;
	cout << &a[1] << endl;
	cout << &a[2] << endl;

	cout << endl;

	cout << &b[0] << endl;
	cout << &b[1] << endl;
	cout << &b[2] << endl;

	return 0;
}
posted @ 2013-05-05 12:27  helloweworld  阅读(281)  评论(0编辑  收藏  举报