博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于静态存储区的理解(自己还处于懵懂的状态呢)
阅读量:4617 次
发布时间:2019-06-09

本文共 1812 字,大约阅读时间需要 6 分钟。

指针对于数组和字符串来说 是其内存的首地址。

  • 首先发现字符型和整形的有点不一样呢
    #define  _CRT_SECURE_NO_WARNINGS #include 
    #include
    #include
    #define DER 100char * getStr1(){ char *p1 = "abcdefg2"; return p1;}char *getStr2(){ char *p2 = "abcdefg2"; return p2;}void main(){ char *p1 = NULL; char *p2 = NULL; int *b1; int *b2; int a=100; b1=&a; b2=&a; p1 = getStr1(); p2 = getStr2(); //打印p1 p2 所指向内存空间的数据 printf("p1:%s , p2:%s \n", p1, p2);//直接显示的是指针内部的值 //打印p1 p2 的值 printf("p1:%d , p2:%d \n", p1, p2);//这里显示的是两个指针指向值地址 printf("b1:%d ,b2:%d \n", b1, b2);//这里显示的是指针指向值的地址 printf("b1:%d ,b2:%d \n", &b1, &b2);//整个数据的地址,如100,12个字节 printf("b1:%d ,b2:%d \n", *b1, *b2);//指针内存放的值 printf("b1:%s ,b2:%s \n", b1, b2);//两个指针所代表的ascii表中的值 printf("hello...\n"); system("pause"); return ;}

      结果为

#include "stdlib.h"#include "stdio.h"#include "string.h"// 数据类型的用途//数据类型的本质:固定大小内存块的别名// b &b 数组数据类型 (定义一个1 数组类型 2数组指针  3 数组类型和数组指针类型的关系) ====>压死初学者的三座大山  抛砖//void main31(){	int a; //告诉c编译器分配4个字节的内存	int b[10] ; //告诉c编译器分配40个自己内存	printf("b:%d, b+1:%d, &b:%d, &b+1:%d \n", b, b+1, &b, &b+1);	printf("sizeof(b):%d \n", sizeof(b));  //40	printf("sizeof(a):%d \n ", sizeof(a)); //4	 	// b+1  &b+1 结果不一样  //b &b所代表的数据类型不一样	//b 代表的数组首元素的地址	//&b代表的是整个数组的地址  	//	printf("hello....\n");	system("pause");}struct Teacher{	char name[64];	int age;}Teacher;typedef struct Teacher2{	char name[64];	int age;}Teacher2;//数据别名 typedeftypedef int u32;void main33(){	int a; //告诉c编译器分配4个字节的内存	int b[10] ; //告诉c编译器分配40个自己内存	struct Teacher t1;	Teacher2 t2;	t1.age = 31;	printf("u32:%d \n", sizeof(u32));	{		char *p2 = NULL;		void *p1 = NULL;		p2 = (char *)malloc(100);		p1 = &p2;	}	{		//void a;//编译器不知道如何分配内存	}	printf("hello....\n");	system("pause");}

  

转载于:https://www.cnblogs.com/xiaochige/p/6637085.html

你可能感兴趣的文章
使用 NPOI 、aspose实现execl模板公式计算
查看>>
行为型模式:中介者模式
查看>>
How to Notify Command to evaluate in mvvmlight
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
个人介绍
查看>>
使用python动态特性时,让pycharm自动补全
查看>>
你必知必会的SQL面试题
查看>>
html5 Canvas绘制时钟以及绘制运动的圆
查看>>
云推送注意(MSDN链接)
查看>>
Metro Style app :浏览器扩展
查看>>
linux的kernel是怎样工作的(TI_DM36X_ARM系统)(1)
查看>>
[luogu4310] 绝世好题 (递推)
查看>>
[luogu3203 HNOI2010] 弹飞绵羊 (分块)
查看>>
mui搜索框 搜索点击事件
查看>>
2016012003+陈琦+散列函数的应用及其安全性
查看>>
Android 状态栏通知Notification、NotificationManager详解
查看>>
UIApplicationDelegate协议
查看>>
Jmeter测试dubbo接口填坑
查看>>