Memory and identifier storage properties of the program (ii)

Source: Internet
Author: User

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", &AMP;PSTR2, PSTR2, PSTR2);
	
	
	printf ("String constant data address pstr3:x%08x points to 0x%08x content is-%s\n", &AMP;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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.