验证C语言内存分配

来源:互联网 发布:c语言倒序输出数字 编辑:程序博客网 时间:2024/05/15 01:19
#include <stdio.h>#include <stdlib.h>static int a;//全局静态变量(静态区)char b[2];//全局普通变量(静态区char *s = "abcdefg";//常量区void test(){     static int c;//局部静态变量(静态区     int d;//局部普通变量(栈区     printf("\nLocal variables:\n");     printf("c    = 0x%.8x\n", c);     printf("d    = 0x%.8x\n", b);     printf("&c   = %p\n", &c);     printf("&d   = %p\n", &d);}int main(int agvc, char* argv[]){     char *p;     if ((p = (char*)malloc(10)) <= 0)          return 0;//no memory in 堆区     test();     printf("\nGloble variables:\n");     printf("a    = 0x%.8x\n", a);     printf("b[0] = 0x%.8x\n", b[0]);     printf("b[1] = 0x%.8x\n", b[1]);     printf("s    = 0x%s\n", s);     printf("&a   = %p\n", &a);     printf("&b[0]= %p\n", &b[0]);     printf("&b[1]= %p\n", &b[1]);     printf("&s = %p\n", s);     printf("&p = %p\n", p);     return 0;}


 

原创粉丝点击