test Code
#include <stdio.h> #include <malloc.h> int g_i = 100;
int g_j = 200;
int G_k, g_h;
int main (int argc, char * argv[]) {const int MAXN = 100;
int *p = (int*) malloc (MAXN * sizeof (int));
int *q = (int*) malloc (MAXN * sizeof (int));
static int s_i = 5;
static int s_j = 10;
static int s_k;
static int s_h;
int i = 5;
int j = 10;
int k = 20;
int F, H;
Char *pstr1 = "Magictong Hello world";
Char *pstr2 = "Magictong Hello world";
Char *PSTR3 = "Hello World";
int * r = (int*) malloc (MAXN * sizeof (int));
printf ("Data address I (with initial value) in stack: x%08x =%d\n", &i, I);
printf ("Data address J (with initial value) in stack: x%08x =%d\n", &j, J);
printf ("Data address K (with initial value) in stack: x%08x =%d\n", &k, K);
printf ("Data address f (no initial value) in stack: x%08x =%d\n", &f, F);
printf ("Data address h (no initial value) in stack: x%08x =%d\n", &h, h);
Putchar (' \ n ');
printf ("Static data address s_i (with initial value): x%08x =%d\n", &s_i, s_i);
printf ("Static data address S_j (with initial value): x%08x =%d\n", &s_j, S_j); printf ("Static data address S_k (no initial value): x%08x =%d\n", &s_k, S_k);
printf ("Static data address S_h (no initial value): x%08x =%d\n", &s_h, S_h);
Putchar (' \ n ');
printf ("Global Data address g_i (with initial value): x%08x =%d\n", &g_i, g_i);
printf ("Global Data address G_j (with initial value): x%08x =%d\n", &g_j, G_j);
printf ("Global Data address G_k (no initial value): x%08x =%d\n", &g_k, G_k);
printf ("Global Data address g_h (no initial value): x%08x =%d\n", &g_h, G_h);
Putchar (' \ n ');
printf ("String constant data address pstr1:x%08x points to 0x%08x content is-%s\n", &pstr1, Pstr1, PSTR1);
printf ("String constant data address pstr2:x%08x points to 0x%08x content is-%s\n", &PSTR2, PSTR2, PSTR2);
printf ("String constant data address pstr3:x%08x points to 0x%08x content is-%s\n", &PSTR3, PSTR3, PSTR3);
Putchar (' \ n ');
printf ("Data address in the heap p:x%08x to point = 0x%08x\n", &p, p);
printf ("Data address in the heap q:x%08x to point = 0x%08x\n", &q, Q);
printf ("Data address in the heap r:x%08x to point = 0x%08x\n", &r, R);
Free (p);
Free (q);
Free (R);
return 0; }
Run Results
The memory of the program and the storage attribute of the identifier (c) are summarized and analyzed.