P14 内存四区的基本原理

#include <iostream>
#include <string>
using namespace std;

char* getStr1()
{
	char *p1 = "abcdefg2";
	return p1;
}

char* getStr2()
{
	char *p2 = "abcdefg";
	return p2;
}

int main()
{
	char *p1 = NULL;
	char *p2 = NULL;

	p1 = getStr1();
	p2 = getStr2();

	//打印p1 p2 所指向内存空间的数据
	printf("p1:%s,p2:%s\n",p1,p2);

	//打印p1 p2的值
	printf("p1:%d,p2:%d\n",p1,p2);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41983807/article/details/87885323