ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡ÔĶÁ¹ý³Ì·¢ÏÖÈκδíÎóÇë¸æËßÎÒÃÇ£¬Ð»Ð»£¡£¡ ±¨¸æ´íÎó
°Ë°ËÊé³Ç ·µ»Ø±¾ÊéĿ¼ ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ½øÈëÊé°É ¼ÓÈëÊéÇ©

[Ãâ·ÑÏÂÔØ cÓïÑÔÉî¶È½âÆÊ[1]-µÚÕÂ

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡



ÔÚÔËÐÐʱ£¬½«¼ÆËã¡¡
b£§10£§µÄʵ¼ÊµØÖ·£¬²¢ÇÒÈ¡Öµ¡£Õâʱºò·¢ÉúÔ½½ç´íÎó¡£

µÚ¶þ£º±àÒëÆ÷µÄ¾¯¸æÒѾ­¸æËßÎÒÃDZàÒëÆ÷ÐèÒªµÄÊÇÒ»¸ö¡¡
char*ÀàÐ͵IJÎÊý£¬¶ø´«µÝ¹ýÈ¥
µÄÊÇÒ»¸ö¡¡
charÀàÐ͵IJÎÊý£¬Õâʱºò¡¡
funº¯Êý»á½«´«ÈëµÄ¡¡
charÀàÐ͵ÄÊý¾Ýµ±µØÖ·´¦Àí£¬Í¬Ñù
»á·¢Éú´íÎó¡££¨ÕâµãÇ°ÃæÒѾ­Ïêϸ½²½â£©

µÚÒ»¸ö´íÎóºÜºÃÀí½â£¬ÄÇôµÚ¶þ¸ö´íÎóÔõôÀí½âÄØ£¿¡¡
funº¯ÊýÃ÷Ã÷´«µÝµÄÊÇÒ»¸öÊý×é°¡£¬
±àÒëÆ÷Ôõô»á˵ÊÇ¡¡
char*ÀàÐÍÄØ£¿±ð¼±£¬ÎÒÃÇÏȰѺ¯ÊýµÄµ÷Ó÷½Ê½¸Ä±äһϣº¡¡


fun£¨b£©£»¡¡


bÊÇÒ»¸öÊý×飬ÏÖÔÚ½«Êý×é¡¡
b×÷Ϊʵ¼Ê²ÎÊý´«µÝ¡£ÕâϸÃûÓÐÎÊÌâÁË°É£¿µ÷ÊÔ¡¢ÔËÐУ¬
Ò»ÇÐÕý³££¬Ã»ÓÐÎÊÌ⣬ÊÕ¹¤£¡ºÜÇáÒ×ÊÇ°É£¿µ«ÊÇÄãÈ·ÈÏÄãÕæÕýÃ÷°×ÁËÕâÊÇÔõô»ØÊ£¿Êý×é¡¡
b¡¡



ÕæµÄ´«µÝµ½Á˺¯ÊýÄÚ²¿£¿

4¡£6¡£1¡£2£¬ÎÞ·¨Ïòº¯Êý´«µÝÒ»¸öÊý×é
ÎÒÃÇÍêÈ«¿ÉÒÔÑé֤һϣº¡¡


void¡¡
fun£¨char¡¡
a£§10£§£©¡¡
£û¡¡


int¡¡
i¡¡
=¡¡
sizeof£¨a£©£»¡¡


charc¡¡
=¡¡
a£§3£§£»¡¡


£ý

Èç¹ûÊý×é¡¡
bÕæÕý´«µÝµ½º¯ÊýÄÚ²¿£¬ÄÇ¡¡
iµÄÖµÓ¦¸ÃΪ¡¡
10¡£µ«ÊÇÎÒÃDzâÊÔºó·¢ÏÖ¡¡
iµÄÖµ¾¹È»
Ϊ¡¡
4£¡ÎªÊ²Ã´»áÕâÑùÄØ£¿ÄѵÀÊý×é¡¡
bÕæµÄûÓд«µÝµ½º¯ÊýÄÚ²¿£¿Êǵģ¬È·ÊµÃ»Óд«µÝ¹ýÈ¥£¬
ÕâÊÇÒòΪÕâÑùÒ»Ìõ¹æÔò£º¡¡


CÓïÑÔÖУ¬µ±Ò»Î¬Êý×é×÷Ϊº¯Êý²ÎÊýµÄʱºò£¬±àÒëÆ÷×ÜÊÇ°ÑËü½âÎö³ÉÒ»¸öÖ¸ÏòÆäÊ×Ôª
ËØÊ×µØÖ·µÄÖ¸Õë¡£

Õâô×öÊÇÓÐÔ­ÒòµÄ¡£ÔÚ¡¡
CÓïÑÔÖУ¬ËùÓзÇÊý×éÐÎʽµÄÊý¾Ýʵ²Î¾ùÒÔ´«ÖµÐÎʽ£¨¶Ôʵ²Î
×öÒ»·Ý¿½±´²¢´«µÝ¸ø±»µ÷Óõĺ¯Êý£¬º¯Êý²»ÄÜÐÞ¸Ä×÷Ϊʵ²ÎµÄʵ¼Ê±äÁ¿µÄÖµ£¬¶øÖ»ÄÜÐÞ¸Ä
´«µÝ¸øËüµÄÄÇ·Ý¿½±´£©µ÷Óá£È»¶ø£¬Èç¹ûÒª¿½±´Õû¸öÊý×飬ÎÞÂÛÔÚ¿Õ¼äÉÏ»¹ÊÇÔÚʱ¼äÉÏ£¬
Æ俪Ïú¶¼ÊǷdz£´óµÄ¡£¸üÖØÒªµÄÊÇ£¬ÔÚ¾ø´ó²¿·ÖÇé¿öÏ£¬ÄãÆäʵ²¢²»ÐèÒªÕû¸öÊý×éµÄ¿½±´£¬
ÄãÖ»Ïë¸æËߺ¯ÊýÔÚÄÇÒ»¿Ì¶ÔÄĸöÌض¨µÄÊý×é¸ÐÐËȤ¡£ÕâÑùµÄ»°£¬ÎªÁ˽Úʡʱ¼äºÍ¿Õ¼ä£¬Ìá
¸ß³ÌÐòÔËÐеÄЧÂÊ£¬ÓÚÊǾÍÓÐÁËÉÏÊöµÄ¹æÔò¡£Í¬ÑùµÄ£¬º¯ÊýµÄ·µ»ØÖµÒ²²»ÄÜÊÇÒ»¸öÊý×飬
¶øÖ»ÄÜÊÇÖ¸Õë¡£ÕâÀïÒªÃ÷È·µÄÒ»¸ö¸ÅÄî¾ÍÊÇ£ºº¯Êý±¾ÉíÊÇûÓÐÀàÐ͵ģ¬Ö»Óк¯ÊýµÄ·µ»ØÖµ
²ÅÓÐÀàÐÍ¡£ºÜ¶àÊ鶼°ÑÕâµãŪ´íÁË£¬ÉõÖÁ³öÏÖ¡°XXXÀàÐ͵ĺ¯Êý¡±ÕâÖÖ˵·¨¡£¼òÖ±ÊÇ»ÄÌÆ
ÖÁ¼«£¡

¾­¹ýÉÏÃæµÄ½âÊÍ£¬ÏàÐÅÄãÒѾ­Àí½âÉÏÊöµÄ¹æ¶¨ÒÔ¼°ËüµÄÀ´ÓÉ¡£ÉÏÃæ±àÒëÆ÷¸ø³öµÄÌáʾ£¬
˵º¯ÊýµÄ²ÎÊýÊÇÒ»¸ö¡¡
char*ÀàÐ͵ÄÖ¸Õ룬ÕâµãÏàÐÅÒ²¿ÉÒÔÀí½â¡£

¼ÈÈ»Èç´Ë£¬ÎÒÃÇÍêÈ«¿ÉÒÔ°Ñ¡¡
funº¯Êý¸Äд³ÉÏÂÃæµÄÑù×Ó£º¡¡


void¡¡
fun£¨char¡¡
*p£©¡¡


£û¡¡


charc¡¡
=¡¡
p£§3£§£»//»òÕßÊÇ¡¡
charc¡¡
=¡¡
*£¨p£«3£©£»¡¡


£ý

ͬÑù£¬Ä㻹¿ÉÒÔÊÔÊÔÕâÑù×Ó£º¡¡


void¡¡
fun£¨char¡¡
a£§10£§£©¡¡


£û¡¡


charc¡¡
=¡¡
a£§3£§£»¡¡


£ý¡¡



intmain£¨£©¡¡


£û¡¡
charb£§100£§=¡¡
¡°abcdefg¡±£»¡¡
fun£¨b£©£»¡¡


return0£»¡¡
£ý


ÔËÐÐÍêȫûÓÐÎÊÌ⡣ʵ¼Ê´«µÝµÄÊý×é´óСÓ뺯ÊýÐβÎÖ¸¶¨µÄÊý×é´óСûÓйØϵ¡£¼ÈÈ»
Èç´Ë£¬ÄÇÎÒÃÇÒ²¿ÉÒÔ¸Äд³ÉÏÂÃæµÄÑù×Ó£º¡¡


void¡¡
fun£¨char¡¡
a£§¡¡
£§£©¡¡
£û¡¡
charc¡¡
=¡¡
a£§3£§£»¡¡
£ý
¸Äд³ÉÕâÑù»òÐí±È½ÏºÃ£¬ÖÁÉÙ²»»áÈÃÈËÎó»á³ÉÖ»ÄÜ´«µÝÒ»¸ö¡¡
10¸öÔªËصÄÊý×é¡£

4¡£6¡£2£¬Ò»¼¶Ö¸Õë²ÎÊý
4¡£6¡£2¡£1£¬ÄÜ·ñ°ÑÖ¸Õë±äÁ¿±¾Éí´«µÝ¸øÒ»¸öº¯Êý
ÎÒÃÇ°ÑÉÏÒ»½ÚÌÖÂÛµÄÁÐ×ÓÔÙ¸ÄдһÏ£º¡¡


void¡¡
fun£¨char¡¡
*p£©¡¡
£û¡¡
charc¡¡
=¡¡
p£§3£§£»//»òÕßÊÇ¡¡
charc¡¡
=¡¡
*£¨p£«3£©£»¡¡
£ý¡¡


intmain£¨£©¡¡


£û¡¡
char*p2¡¡
=¡¡
¡°abcdefg¡±£»¡¡
fun£¨p2£©£»¡¡
return0£»¡¡


£ý
Õâ¸öº¯Êýµ÷Óã¬ÕæµÄ°Ñ¡¡
p2±¾Éí´«µÝµ½ÁË¡¡
funº¯ÊýÄÚ²¿Âð£¿
ÎÒÃÇÖªµÀ¡¡
p2ÊÇ¡¡
mainº¯ÊýÄÚµÄÒ»¸ö¾Ö²¿±äÁ¿£¬ËüÖ»ÔÚ¡¡
mainº¯ÊýÄÚ²¿ÓÐЧ¡££¨ÕâÀïÐèÒª

³ÎÇåÒ»¸öÎÊÌ⣺mainº¯ÊýÄڵıäÁ¿²»ÊÇÈ«¾Ö±äÁ¿£¬¶øÊǾֲ¿±äÁ¿£¬Ö»²»¹ýËüµÄÉúÃüÖÜÆÚºÍ


È«¾Ö±äÁ¿Ò»Ñù³¤¶øÒÑ¡£È«¾Ö±äÁ¿Ò»¶¨ÊǶ¨ÒåÔÚº¯ÊýÍⲿµÄ¡£³õѧÕßÍùÍùŪ´íÕâµã¡££©¼ÈÈ»Ëü
ÊǾֲ¿±äÁ¿£¬funº¯Êý¿Ï¶¨ÎÞ·¨Ê¹Óá¡
p2µÄÕæÉí¡£ÄǺ¯Êýµ÷ÓÃÔõô°ì£¿ºÃ°ì£º¶Ôʵ²Î×öÒ»·Ý
¿½±´²¢´«µÝ¸ø±»µ÷Óõĺ¯Êý¡£¼´¶Ô¡¡
p2×öÒ»·Ý¿½±´£¬¼ÙÉèÆ俽±´ÃûΪ_p2¡£ÄÇ´«µÝµ½º¯ÊýÄÚ
²¿µÄ¾ÍÊÇ_p2¶ø²¢·Ç¡¡
p2±¾Éí¡£

4¡£6¡£2¡£2£¬ÎÞ·¨°ÑÖ¸Õë±äÁ¿±¾Éí´«µÝ¸øÒ»¸öº¯Êý
ÕâºÜÏñËïÎò¿Õ°ÎÏÂÒ»¸ùºïë±ä³É×Ô¼ºµÄÑù×ÓÈ¥ºöÓÆСÑý¹Ö¡£ËùÒÔ¡¡
funº¯Êýʵ¼ÊÔËÐÐʱ£¬
Óõ½µÄ¶¼ÊÇ_p2Õâ¸ö±äÁ¿¶ø·Ç¡¡
p2±¾Éí¡£Èç´Ë£¬ÎÒÃÇ¿´ÏÂÃæµÄÀý×Ó£º¡¡
voidGetMemory£¨char*¡¡
p£»intnum£©¡¡
£û¡¡
p¡¡
=¡¡
£¨char*£©malloc£¨num*sizeof£¨char£©£©£»¡¡
£ý¡¡


intmain£¨£©¡¡


£û¡¡


char*str=¡¡
NULL£»¡¡


GetMemory£¨str£¬10£©£»¡¡


strcpy£¨str£»¡±hello¡±£©£»¡¡


free£¨str£©£»//free²¢Ã»ÓÐÆð×÷Óã¬ÄÚ´æй©¡¡


return0£»¡¡
£ý
ÔÚÔËÐС¡
strcpy£¨str£»¡±hello¡±£©Óï¾äµÄʱºò·¢Éú´íÎó¡£Õâʱºò¹Û²ì¡¡
strµÄÖµ£¬·¢ÏÖÈÔȻΪ¡¡
NULL¡£
Ò²¾ÍÊÇ˵¡¡
str±¾Éí²¢Ã»Óиı䣬ÎÒÃÇ¡¡
mallocµÄÄÚ´æµÄµØÖ·²¢Ã»Óи³¸ø¡¡
str£¬¶øÊǸ³¸øÁË_str¡£
¶øÕâ¸ö_strÊDZàÒëÆ÷×Ô¶¯·ÖÅäºÍ»ØÊյģ¬ÎÒÃǸù±¾¾ÍÎÞ·¨Ê¹Óá£ËùÒÔÏëÕâÑù»ñÈ¡Ò»¿éÄÚ´æÊÇ

²»Ðеġ£ÄÇÔõô°ì£¿Á½¸ö°ì·¨£º

µÚÒ»£ºÓá¡
return¡£¡¡


char*¡¡
GetMemory£¨char*¡¡
p£»intnum£©¡¡


£û¡¡


p¡¡
=¡¡
£¨char*£©malloc£¨num*sizeof£¨char£©£©£»¡¡
returnp£»¡¡
£ý¡¡


intmain£¨£©¡¡
£û¡¡



char*str=¡¡
NULL£»¡¡
str=GetMemory£¨str£¬10£©£»¡¡
strcpy£¨str£»¡±hello¡±£©£»¡¡
free£¨str£©£»¡¡


return0£»¡¡
£ý


Õâ¸ö·½·¨¼òµ¥£¬ÈÝÒ×Àí½â¡£
µÚ¶þ£ºÓöþ¼¶Ö¸Õë¡£¡¡
voidGetMemory£¨char**¡¡
p£»intnum£©¡¡
£û¡¡


*p¡¡
=¡¡
£¨char*£©malloc£¨num*sizeof£¨char£©£©£»¡¡
returnp£»¡¡
£ý¡¡


intmain£¨£©¡¡


£û¡¡
char*str=¡¡
NULL£»¡¡
GetMemory£¨&str£¬10£©£»¡¡
strcpy£¨str£»¡±hello¡±£©£»¡¡
free£¨str£©£»¡¡
return0£»¡¡


£ý
×¢Ò⣬ÕâÀïµÄ²ÎÊýÊÇ¡¡
&str¶ø·Ç¡¡
str¡£ÕâÑùµÄ»°´«µÝ¹ýÈ¥µÄÊÇ¡¡
strµÄµØÖ·£¬ÊÇÒ»¸öÖµ¡£ÔÚº¯
ÊýÄÚ²¿£¬ÓÃÔ¿³×£¨¡¡
¡°*¡±£©À´¿ªËø£º¡¡
*£¨&str£©£¬ÆäÖµ¾ÍÊÇ¡¡
str¡£ËùÒÔ¡¡
malloc·ÖÅäµÄÄÚ´æµØÖ·ÊÇÕæÕý
¸³Öµ¸øÁË¡¡
str±¾Éí¡£
ÁíÍâ¹ØÓÚ¡¡
mallocºÍ¡¡
freeµÄ¾ßÌåÓ÷¨£¬ÄÚ´æ¹ÜÀíÄÇÕÂÓÐÏêϸÌÖÂÛ¡£

4¡£6¡£3£¬¶þάÊý×é²ÎÊýÓë¶þάָÕë²ÎÊý
Ç°ÃæÏêϸ·ÖÎöÁ˶þάÊý×éÓë¶þάָÕ룬ÄÇËüÃÇ×÷Ϊ²ÎÊýʱÓë²»×÷Ϊ²ÎÊýʱÓÖÓÐʲôÇø
±ðÄØ£¿¿´Àý×Ó£º¡¡


voidfun£¨chara£§3£§£§4£§£©£»¡¡



ÎÒÃÇ°´ÕÕÉÏÃæµÄ·ÖÎö£¬ÍêÈ«¿ÉÒÔ°Ñ¡¡
a£§3£§£§4£§Àí½âΪһ¸öһάÊý×é¡¡
a£§3£§£¬Æäÿ¸öÔªËض¼ÊÇÒ»
¸öº¬ÓС¡
4¸ö¡¡
charÀàÐÍÊý¾ÝµÄÊý×é¡£ÉÏÃæµÄ¹æÔò£¬¡¡
¡°CÓïÑÔÖУ¬µ±Ò»Î¬Êý×é×÷Ϊº¯Êý²ÎÊýµÄʱ
ºò£¬±àÒëÆ÷×ÜÊÇ°ÑËü½âÎö³ÉÒ»¸öÖ¸ÏòÆäÊ×ÔªËØÊ×µØÖ·µÄÖ¸Õë¡£¡±ÔÚÕâÀïͬÑùÊÊÓã¬Ò²¾ÍÊÇ˵
ÎÒÃÇ¿ÉÒÔ°ÑÕâ¸öº¯ÊýÉùÃ÷¸ÄдΪ£º¡¡


voidfun£¨char¡¡
£¨*p£©£§4£§£©£»

ÕâÀïµÄÀ¨ºÅ¾ø¶Ô²»ÄÜÊ¡ÂÔ£¬ÕâÑù²ÅÄܱ£Ö¤±àÒëÆ÷°Ñ¡¡
p½âÎöΪһ¸öÖ¸Ïò°üº¬¡¡
4¸ö¡¡
charÀà

ÐÍÊý¾ÝÔªËصÄÊý×飬¼´Ò»Î¬Êý×é¡¡
a£§3£§µÄÔªËØ¡£

ͬÑù£¬×÷Ϊ²ÎÊýʱ£¬Ò»Î¬Êý×é¡°£§£§¡±ºÅÄÚµÄÊý×ÖÍêÈ«¿ÉÒÔÊ¡ÂÔ£º¡¡


voidfun£¨chara£§£§£§4£§£©£»
²»¹ýµÚ¶þάµÄάÊýÈ´²»¿ÉÊ¡ÂÔ£¬ÏëÏëΪʲô²»¿ÉÒÔÊ¡ÂÔ£¿
×¢Ò⣺Èç¹û°ÑÉÏÃæÌáµ½µÄÉùÃ÷¡¡
void¡¡
fun£¨char¡¡
£¨*p£©£§4£§£©ÖеÄÀ¨ºÅÈ¥µôÖ®ºó£¬ÉùÃ÷¡°void¡¡
fun£¨char¡¡
*p£§4£§£©¡±¿ÉÒÔ¸Äд³É£º¡¡
voidfun£¨char**p£©£»

ÕâÊÇÒòΪ²ÎÊý*p£§4£§£¬¶ÔÓÚ¡¡
pÀ´Ëµ£¬ËüÊÇÒ»¸ö°üº¬¡¡
4¸öÖ¸ÕëµÄһάÊý×飬ͬÑù°ÑÕâ¸öһάÊý
×éÒ²¸ÄдΪָÕëµÄÐÎʽ£¬ÄǾ͵õ½ÉÏÃæµÄд·¨¡£
ÉÏÃæÌÖÂÛÁËÕâô¶à£¬ÄÇÎÒÃǰѶþάÊý×é²ÎÊýºÍ¶þάָÕë²ÎÊýµÄµÈЧ¹ØϵÕûÀíһϣº

Êý×é²ÎÊýµÈЧµÄÖ¸Õë²ÎÊý
Êý×éµÄÊý×飺char¡¡
a£§3£§£§4£§Êý×éµÄÖ¸Õ룺char¡¡
£¨*p£©£§10£§
Ö¸ÕëÊý×飺¡¡
char¡¡
*a£§5£§Ö¸ÕëµÄÖ¸Õ룺char¡¡
**p¡¡


ÕâÀïÐèҪעÒâµÄÊÇ£ºCÓïÑÔÖУ¬µ±Ò»Î¬Êý×é×÷Ϊº¯Êý²ÎÊýµÄʱºò£¬±àÒëÆ÷×ÜÊÇ°ÑËü½âÎö
³ÉÒ»¸öÖ¸ÏòÆäÊ×ÔªËØÊ×µØÖ·µÄÖ¸Õë¡£ÕâÌõ¹æÔò²¢²»ÊǵݹéµÄ£¬Ò²¾ÍÊÇ˵ֻÓÐһάÊý×é²ÅÊÇ
Èç´Ë£¬µ±Êý×é³
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨0£©
δÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡