c ÓïÑÔÖеÄstatic
1. static ±äÁ¿
¾²Ì¬±äÁ¿µÄÀàÐÍ ËµÃ÷·ûÊÇstatic¡£ ¾²Ì¬±äÁ¿µ±È»ÊÇÊôÓÚ¾²Ì¬´æ´¢·½Ê½£¬µ«ÊÇÊôÓÚ¾²Ì¬´æ´¢·½Ê½µÄÁ¿²»Ò»¶¨¾ÍÊǾ²Ì¬±äÁ¿¡£ ÀýÈçÍⲿ±äÁ¿ËäÊôÓÚ¾²Ì¬ ´æ´¢·½Ê½£¬µ«²»Ò»¶¨ÊǾ²Ì¬±äÁ¿£¬±ØÐëÓÉ static¼ÓÒÔ¶¨Òåºó²ÅÄܳÉΪ¾²Ì¬Íⲿ±äÁ¿£¬»ò³Æ¾²Ì¬È«¾Ö±äÁ¿¡£
2. ¾²Ì¬¾Ö²¿±äÁ¿
¾²Ì¬¾Ö²¿±äÁ¿ÊôÓÚ¾²Ì¬´æ´¢·½Ê½£¬Ëü¾ßÓÐÒÔÏÂÌص㣺
(1)¾²Ì¬¾Ö²¿±äÁ¿ÔÚº¯ÊýÄÚ¶¨Òå ËüµÄÉú´æÆÚΪÕû¸öÔ´³ÌÐò£¬µ«ÊÇÆä×÷ÓÃÓòÈÔÓë×Ô¶¯±äÁ¿Ïàͬ£¬Ö»ÄÜÔÚ¶¨Òå¸Ã±äÁ¿µÄº¯ÊýÄÚʹÓøñäÁ¿¡£Í˳ö¸Ãº¯Êýºó£¬ ¾¡¹Ü¸Ã±äÁ¿»¹¼ÌÐø´æÔÚ£¬µ«²»ÄÜʹÓÃËü¡£
(2)ÔÊÐí¶Ô¹¹ÔìÀྲ̬¾Ö²¿Á¿¸³³õÖµ ÀýÈçÊý×飬Èôδ¸³ÒÔ³õÖµ£¬ÔòÓÉϵͳ×Ô¶¯¸³ÒÔ0Öµ¡£
(3)¶Ô»ù±¾ÀàÐ͵ľ²Ì¬¾Ö²¿±äÁ¿ÈôÔÚ˵Ã÷ʱδ¸³ÒÔ³õÖµ£¬Ôòϵͳ×Ô¶¯¸³Óè0Öµ¡£¶ø¶Ô×Ô¶¯±äÁ¿²»¸³³õÖµ£¬ÔòÆäÖµÊDz»¶¨µÄ¡£ ¸ù¾Ý¾²Ì¬¾Ö²¿±äÁ¿µÄÌص㣬 ¿ÉÒÔ ¿´³öËüÊÇÒ»ÖÖÉú´æÆÚΪÕû¸öÔ´³ÌÐòµÄÁ¿¡£ËäÈ»À뿪¶¨ÒåËüµÄº¯Êýºó²»ÄÜʹÓ㬵«ÈçÔٴε÷Óö¨ÒåËüµÄº¯Êýʱ£¬ËüÓֿɼÌÐøʹÓ㬠¶øÇÒ±£´æÁËÇ°´Î±»µ÷ÓúóÁôÏÂµÄ Öµ¡£ Òò´Ë£¬µ±¶à´Îµ÷ÓÃÒ»¸öº¯ÊýÇÒÒªÇóÔÚµ÷ÓÃÖ®¼ä±£ÁôijЩ±äÁ¿µÄֵʱ£¬¿É¿¼ÂDzÉÓþ²Ì¬¾Ö²¿±äÁ¿¡£ËäÈ»ÓÃÈ«¾Ö±äÁ¿Ò²¿ÉÒÔ´ïµ½ÉÏÊöÄ¿µÄ£¬µ«È«¾Ö±äÁ¿ÓÐʱ»áÔì³É ÒâÍâµÄ¸±×÷Óã¬Òò´ËÈÔÒÔ²ÉÓþֲ¿¾²Ì¬±äÁ¿ÎªÒË¡£
3.¾²Ì¬È«¾Ö±äÁ¿
È«¾Ö±äÁ¿(Íⲿ±äÁ¿)µÄ˵Ã÷֮ǰÔÙ¹ÚÒÔstatic ¾Í¹¹ ³ÉÁ˾²Ì¬µÄÈ«¾Ö±äÁ¿¡£È«¾Ö±äÁ¿±¾Éí¾ÍÊǾ²Ì¬´æ´¢·½Ê½£¬ ¾²Ì¬È«¾Ö±äÁ¿µ±È»Ò²ÊǾ²Ì¬´æ´¢·½Ê½¡£ ÕâÁ½ÕßÔÚ´æ´¢·½Ê½Éϲ¢ÎÞ²»Í¬¡£ÕâÁ½ÕßµÄÇø±ðËäÔÚÓڷǾ²Ì¬È«¾Ö ±äÁ¿µÄ×÷ÓÃÓòÊÇÕû¸öÔ´³ÌÐò£¬ µ±Ò»¸öÔ´³ÌÐòÓɶà¸öÔ´Îļþ×é³Éʱ£¬·Ç¾²Ì¬µÄÈ«¾Ö±äÁ¿ÔÚ¸÷¸öÔ´ÎļþÖж¼ÊÇÓÐЧµÄ¡£ ¶ø¾²Ì¬È«¾Ö±äÁ¿ÔòÏÞÖÆÁËÆä×÷ÓÃÓò£¬ ¼´Ö»ÔÚ ¶¨Òå¸Ã±äÁ¿µÄÔ´ÎļþÄÚÓÐЧ£¬ ÔÚͬһԴ³ÌÐòµÄÆäËüÔ´ÎļþÖв»ÄÜʹÓÃËü¡£ÓÉÓÚ¾²Ì¬È«¾Ö±äÁ¿µÄ×÷ÓÃÓò¾ÖÏÞÓÚÒ»¸öÔ´ÎļþÄÚ£¬Ö»ÄÜΪ¸ÃÔ´ÎļþÄڵĺ¯Êý¹«Ó㬠Òò´Ë ¿ÉÒÔ±ÜÃâÔÚÆäËüÔ´ÎļþÖÐÒýÆð´íÎó¡£´ÓÒÔÉÏ·ÖÎö¿ÉÒÔ¿´³ö£¬ °Ñ¾Ö²¿±äÁ¿¸Ä±äΪ¾²Ì¬±äÁ¿ºóÊǸıäÁËËüµÄ´æ´¢·½Ê½¼´¸Ä±äÁËËüµÄÉú´æÆÚ¡£°ÑÈ«¾Ö±äÁ¿¸Ä±äΪ¾²Ì¬±äÁ¿ ºóÊǸıäÁËËüµÄ×÷ÓÃÓò£¬ ÏÞÖÆÁËËüµÄʹÓ÷¶Î§¡£Òò´Ëstatic Õâ¸ö˵Ã÷·ûÔÚ²»Í¬µÄµØ·½ËùÆðµÄ×÷ÓÃÊDz»Í¬µÄ¡£
4. static º¯Êý…..
ÄÚ²¿º¯ÊýºÍÍⲿº¯Êý
µ±Ò»¸öÔ´³ÌÐòÓɶà¸öÔ´Îļþ×é³Éʱ£¬£ÃÓïÑÔ¸ù¾Ýº¯ÊýÄÜ·ñ±»ÆäËüÔ´ÎļþÖеĺ¯Êýµ÷Ó㬽«º¯Êý·ÖΪÄÚ²¿º¯ÊýºÍÍⲿº¯Êý¡£
1 ÄÚ²¿º¯Êý£¨Óֳƾ²Ì¬º¯Êý£©
Èç¹ûÔÚÒ»¸öÔ´ÎļþÖж¨ÒåµÄº¯Êý£¬Ö»Äܱ»±¾ÎļþÖеĺ¯Êýµ÷Ó㬶ø²
Ïà¹ØÎĵµ£º
C++ÄÚ´æ·ÖÅäÃؼ®—new£¬malloc£¬GlobalAllocÏê½â
......
C/C+ÓïÑÔstructÉî²ã̽Ë÷
×÷ÕߣºËᦻª ³ö´¦£ºPConline
1. structµÄ¾Þ´ó×÷ÓÃ
¡¡¡¡Ãæ¶ÔÒ»¸öÈ˵ĴóÐÍC/C++³ÌÐòʱ£¬Ö ......
´æ´¢ÆÚstorage duration(extent)£¬ ָΪ¶ÔÏóÅäÖõÄÄÚ´æµÄ´æ»îÆÚ£¬±ÈÈçlocal extent
Éú´æ¿Õ¼äscope£¬Ö¸¶ÔÏóÔÚ³ÌÐòÄڵĴæ»îÇøÓò£¬¼´¿É±»·ÃÎʵķ¶Î§£¬±ÈÈçfile scope, static scope, local scope
C
local static object
º¯ÊýÄÚ²¿µÄobject£¬¾ßÓÐlocal scope£¬µ«ÊÇÿ´Îº¯Êý±»µ÷Óúó¸Ã¶ÔÏóµÄÄÚ´æ²»ÇåÀí£¬µ½Ï´ε÷Óû¹±£ ......
¹þ¹þ£¡ÓÐÐÒÔÚijÍøÕ¾·¢ÏÖÕâƪÎÄÕ£¬¶Á°Õ£¬¾õµÃÂùÓеÀÀí£¬·¢À´´ó¼ÒÒ»Æð¹²ÃãÖ®
×ÜÊDZ»Í¬Ñ§ÃÇÎʵ½£¬ÈçºÎѧϰCºÍC++²Å²»Ã£È»£¬²Å²»ÊÇÂÒѧ£¬ÏëÁËһϣ¬ÕâÀï¸ø³öÒ»¸ö×ܵĻظ´¡£
¡¡¡¡Ò»¼ÒÖ®ÑÔ£¬»¶ÓÅÄש¹þ¡£
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC.
¡¡¡¡´ó¶àÊýʱºò£¬ÎÒÃÇѧϰÓïÑÔµÄÄ¿µÄ£¬²»ÊÇΪÁ˳ÉΪһ¸öÓïÑÔר¼Ò£¬¶øÊÇÏ£Íû³ÉΪһ¸ö½â¾ ......