CµÄÄÚ´æ·ÖÅäÊÍ·Å·½Ê½Ñ§Ï°
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö
1¡¢Õ»Çø£¨stack£©— ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å
£¬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£
2¡¢¶ÑÇø£¨heap£© — Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å
£¬
Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøʱ¿ÉÄÜÓÉOS»ØÊÕ ¡£×¢ÒâËüÓëÊý¾Ý½á¹¹ÖеĶÑÊÇÁ½»ØÊ£¬·ÖÅ䷽ʽµ¹ÊÇÀàËÆÓÚÁ´±í¡£
3¡¢È«¾ÖÇø£¨¾²Ì¬Çø£©
£¨static£©—£¬È«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿µÄ´æ´¢ÊÇ·ÅÔÚÒ»¿éµÄ£¬³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿ÔÚÒ»¿éÇøÓò£¬
δ³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍδ³õʼ»¯µÄ¾²Ì¬±äÁ¿ÔÚÏàÁÚµÄÁíÒ»¿éÇøÓò¡£ - ³ÌÐò½áÊøºóÓÉϵͳÊÍ·Å
4¡¢ÎÄ×Ö³£Á¿Çø —³£Á¿×Ö·û´®¾ÍÊÇ·ÅÔÚÕâÀïµÄ¡£
³ÌÐò½áÊøºóÓÉϵͳÊÍ·Å
5¡¢³ÌÐò´úÂëÇø—´æ·Åº¯ÊýÌåµÄ¶þ½øÖÆ´úÂë¡£
¶þ¡¢Àý×Ó³ÌÐò
ÕâÊÇÒ»¸öÇ°±²Ð´µÄ£¬·Ç³£Ïêϸ
//main.cpp
int a = 0; È«¾Ö³õʼ»¯Çø
char
*p1; È«¾Öδ³õʼ»¯Çø
main()
{
int b; Õ»
char s[] = "abc"; Õ»
char
*p2; Õ»
char *p3 = "123456"; 123456ÔÚ³£Á¿Çø£¬p3ÔÚÕ»ÉÏ¡£
static int c =0£»
È«¾Ö£¨¾²Ì¬£©³õʼ»¯Çø
p1 = (char *)malloc(10);
p2 = (char *)malloc(20);
·Ö
ÅäµÃÀ´µÃ10ºÍ20×Ö½ÚµÄÇøÓò¾ÍÔÚ¶ÑÇø¡£
strcpy(p1, "123456");
123456·ÅÔÚ³£Á¿Çø£¬±àÒëÆ÷¿ÉÄܻὫËüÓëp3ËùÖ¸ÏòµÄ"123456"ÓÅ»¯³ÉÒ»¸öµØ·½¡£
}
¶þ¡¢¶ÑºÍÕ»µÄÀíÂÛ֪ʶ
2.1ÉêÇ뷽ʽ
stack:
ÓÉϵͳ×Ô¶¯·ÖÅä¡£ ÀýÈ磬ÉùÃ÷ÔÚº¯ÊýÖÐÒ»¸ö¾Ö²¿±äÁ¿
int b; ϵͳ×Ô¶¯ÔÚÕ»ÖÐΪb¿ª±Ù¿Õ¼ä
heap:
ÐèÒª³ÌÐòÔ±×Ô¼ºÉêÇ룬²¢Ö¸Ã÷´óС£¬ÔÚcÖÐmallocº¯Êý
Èçp1 =
(char *)malloc(10);
ÔÚC++ÖÐÓÃnewÔËËã·û
Èçp2 = (char *)malloc(10);
µ«
ÊÇ×¢Òâp1¡¢p2±¾ÉíÊÇÔÚÕ»Öеġ£
2.2
ÉêÇëºóϵͳµÄÏìÓ¦
Õ»£ºÖ»ÒªÕ»µÄÊ£Óà¿Õ¼ä´óÓÚËùÉêÇë¿Õ¼ä£¬ÏµÍ³½«Îª³ÌÐòÌṩÄڴ棬·ñÔò½«±¨Òì³£ÌáʾջÒç³ö¡£
¶Ñ£º
Ê×ÏÈÓ¦¸ÃÖªµÀ²Ù×÷ϵͳÓÐÒ»¸ö¼Ç¼¿ÕÏÐÄÚ´æµØÖ·µÄÁ´±í£¬µ±ÏµÍ³ÊÕµ½³ÌÐòµÄÉêÇëʱ£¬
»á±éÀú¸ÃÁ´±í£¬Ñ°ÕÒµÚÒ»¸ö¿Õ¼ä´óÓÚËùÉêÇë¿Õ¼äµÄ¶Ñ½áµã£¬È»ºó½«¸Ã
½áµã´Ó¿ÕÏнáµãÁ´±íÖÐɾ³ý£¬²¢½«¸Ã½áµãµÄ¿Õ¼ä·ÖÅä¸ø³ÌÐò£¬ÁíÍ⣬¶ÔÓÚ´ó¶àÊýϵͳ£¬»áÔÚÕâ¿éÄÚ´æ¿Õ¼äÖеÄÊ×µØÖ·´¦¼Ç¼±¾´Î·ÖÅäµÄ´óС£¬ÕâÑù£¬´úÂëÖеÄ
deleteÓï¾ä²ÅÄÜÕýÈ·µÄÊͷű¾ÄÚ´æ¿Õ¼ä¡£ÁíÍ⣬ÓÉÓÚÕÒµ½µÄ¶Ñ½áµãµÄ´óС²»Ò»¶¨ÕýºÃµÈÓÚÉêÇëµÄ´óС£¬ÏµÍ³»á×Ô¶¯µÄ½«¶àÓàµÄÄDz¿·ÖÖØзÅÈë¿ÕÏÐÁ´±íÖС£
2.3ÉêÇë´óСµ
Ïà¹ØÎĵµ£º
ÔÚµ±½ñǶÈëʽ“ÎäÁÖ”ÖУ¬Á÷´«×ż¸±¾ÈËÈ˶¼Ïë͵ѧ¼¸ÕеÄCÓïÑÔµÄÎ书Ãؼ®¡£ÕâЩÃؼ®¶¼ÊÇ¿õÊÀÎäѧÆæ²ÅºÄ¾¡±ÏÉú¾«Á¦ËùÖø£¬²¿·ÖÃؼ®Á÷¾ÊýÊ®ÔØÈÔ¾¾Ã²»Ë¥£¬ÈÃËüµÄÎÞÊýʵϰÕßÊÜÒæ·Ëdz¡£¡¡¡¡½ñÌ죬³ÐÃÉÎäÁÖ´ó»áËùÍÏ£¬ÔÚÕ⹫²¼Õ⼸±¾¹ØÓÚCµÄ“¾Ê锣¬Èøü¶àÈËʵϰ֮£¬Á·¾ÍÒ»Éí¾øÊÀµÄǶÈëʽCÓïÑԺù¦·ò¡£Î书à ......
1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2). ¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³£Êý±í´ïʽµÄÖµ£¬Òò´Ë£¬Ö±½Óд³öÄãÊÇÈçºÎ¼ÆËãÒ»ÄêÖÐÓж ......
±àÒëNative CµÄhello,worldÄ£¿é
Android ±àÒë»·¾³±¾Éí±È½Ï¸´ÔÓ£¬ÇÒ²»ÏñÆÕͨµÄ±àÒë»·¾³£ºÖ»Óж¥²ãĿ¼Ï²ÅÓÐMakefileÎļþ£¬¶øÆäËûµÄÿ¸öcomponent¶¼Ê¹ÓÃͳһ±ê×¼µÄ Android.mk. Android.mkÎļþ±¾ÉíÊDZȽϼòµ¥µÄ£¬²»¹ýËü²¢²»ÊÇÎÒÃÇÊìϤµÄMakefile£¬¶øÊǾ¹ýÁËAndroid×ÔÉí±àÒëϵͳµÄºÜ¶à´¦Àí£¬Òò´ËÒªÕæÕýÀ ......
exercise2.4
void squeeze(char s[],char t[])
{
int i,j,k;
int lens,lent;
lens=strlen(s);
lent=strlen(t);
for(i=0,k=0;i<lens;i++)
{
for(j=0;j<lent;j++)
if(s[i]==t[j])
break;
if(j==lent)
s[k++]=s[i];
}
s[k]='\0';
}
exercise2.5
int any(char s[],char t[ ......
2008-06-05 12:38------------------------------------------------------------------------------------------------
º¯ÊýÖ¸Õëͨ³£ÓÃÀ´ÊµÏֻص÷£¬Æä»ù±¾Ó÷¨ÈçÏ£º
1¡¢¶¨Ò庯ÊýÖ¸ÕëÀàÐÍ
// ¶¨ÒåÒ»¸öÔÐÍΪint Fun( int a );µÄº¯ÊýÖ¸Õë
typedef int (*PTRFUN) ( int aPara );
2¡¢º¯ÊýÖ¸Õë±äÁ¿µ ......