全局区理解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38877910/article/details/85327858
#include "stdio.h"

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

char *getStr2()
{
	char *p2 = "abcdefg2";
	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);
}

结论:

  1. 指针指向谁,就把谁的地址赋给指针
  2. 指针变量 和 他所指向的内存空间变量是两个不同的概念

猜你喜欢

转载自blog.csdn.net/weixin_38877910/article/details/85327858