ceÔõôÕÒµ½×¼È·µÄµØµãÖµ
»ñȡ׼ȷµÄµØµãÖµµÄÒªÁìÓУºÊ¹ÓÃÖ¸Õ루& ÔËËã·û£©Ê¹ÓÃÒýÓã¨& ·ûºÅ£©Ê¹ÓõصãÔËËã·û£¨&£©Çå¾²×¢ÖØÊÂÏ¼ì²éÖ¸ÕëºÍÒýÓÃÊÇ·ñÓÐÓò»Òª¶ÔÖ¸Õë¾ÙÐÐËãÊõÔËËã×èÖ¹Ö¸ÏòÁè¼Ý¹æÄ£µÄµØµã
ÔõÑù»ñȡ׼ȷµÄµØµãÖµ
СÐò:
׼ȷµÄµØµãÖµ¹ØÓÚ»á¼ûºÍ²Ù×÷ÄÚ´æÖеÄÊý¾ÝÖÁ¹ØÖ÷Òª¡£±¾ÎĽ«Ì½ÌÖÔÚ C++ ³ÌÐòÖлñȡ׼ȷµØµãÖµµÄÒªÁì¡£
ÒªÁì 1£ºÊ¹ÓÃÖ¸Õë
Ö¸ÕëÊÇÒ»¸öÖ¸ÏòÁíÒ»¸ö±äÁ¿µØµãµÄ±äÁ¿¡£Òª»ñÈ¡µØµãÖµ£¬¿ÉÒÔʹÓà & ÔËËã·û£¬ÈçÏÂËùʾ£º
int x = 10; int* ptr = &x; cout <p><strong>ÒªÁì 2£ºÊ¹ÓÃÒýÓÃ</strong></p><p>ÒýÓÃÒ²ÊÇÒ»¸öÖ¸ÏòÁíÒ»¸ö±äÁ¿µØµãµÄ±äÁ¿£¬µ«ÓëÖ¸Õë²î±ð£¬ÒýÓñØÐè³õʼ»¯ÎªÒ»¸ö±£´æµÄ±äÁ¿¡£Òª»ñÈ¡µØµãÖµ£¬¿ÉÒÔʹÓà & ·ûºÅ£¬ÈçÏÂËùʾ£º</p><pre class="brush:php;toolbar:false">int x = 10; int& ref = x; cout <p><strong>ÒªÁì 3£ºÊ¹ÓõصãÔËËã·û (&)</strong></p><p>& ÔËËã·û¿ÉÓÃÓÚ»ñÈ¡±äÁ¿µÄµØµãÖµ¡£¸ÃÔËËã·û½«·µ»ØÖ¸Ïò±äÁ¿µÄÖ¸Õë¡£ÈçÏÂÀýËùʾ£º</p><pre class="brush:php;toolbar:false">int x = 10; cout <p><strong>Çå¾²×¢ÖØÊÂÏî</strong></p><p>ÔÚʹÓõصãֵʱ£¬ÐèҪעÖØÒÔÏÂÇå¾²×¢ÖØÊÂÏ</p>
µÇ¼ºó¸´ÖÆ
- ʼÖÕ¼ì²éÖ¸ÕëºÍÒýÓÃÊÇ·ñÓÐÓã¬ÒÔ×èÖ¹¶Î¹ýʧ¡£
- ²»Òª¶ÔÖ¸Õë¾ÙÐÐËãÊõÔËË㣬³ý·ÇÄãÖªµÀÈ·ÇеÄÊý¾ÝÀàÐͺÍÄÚ´æ½á¹¹¡£
- ×èÖ¹Ö¸ÏòÁè¼ÝÊý×é»òÆäËûÊý¾Ý½á¹¹¹æÄ£µÄµØµã¡£
ÒÔÉϾÍÊÇceÔõôÕÒµ½×¼È·µÄµØµãÖµµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£