{"id":6136,"date":"2024-03-16T07:01:01","date_gmt":"2024-03-15T23:01:01","guid":{"rendered":""},"modified":"2024-03-16T07:01:01","modified_gmt":"2024-03-15T23:01:01","slug":"\u6307\u9488\u548c\u5f15\u7528\u8be6\u89e3---\u57fa\u7840\u7bc7","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6136.html","title":{"rendered":"\u6307\u9488\u548c\u5f15\u7528\u8be6\u89e3---\u57fa\u7840\u7bc7"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u6307\u9488<\/strong><\/p>\n

    \n
  1. C++\u6bcf\u4e2a\u53d8\u91cf\u90fd\u6709\u4e00\u4e2a\u5185\u5b58\u4f4d\u7f6e\uff0c\u6bcf\u4e2a\u5185\u5b58\u4f4d\u7f6e\u90fd\u5b9a\u4e49\u4e86\u4e00\u4e2a\u53ef\u7528&\u8bbf\u95ee\u7684\u5730\u5740\uff0c\u8868\u793a\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u5730\u5740\uff0c&a\u8868\u793a\u53d8\u91cfa\u7684\u5730\u5740<\/li>\n
  2. \u6307\u9488\u672c\u8eab\u662f\u4e00\u4e2a\u5bf9\u8c61<\/mark>\uff08\u662f\u4e00\u4e2a\u53d8\u91cf<\/mark>\uff09\uff0c\u4ed6\u7684\u503c\u662f\u53e6\u4e00\u4e2a\u53d8\u91cf\u7684\u5730\u5740<\/mark>\uff0c\u6307\u5411\u4e00\u5757\u5185\u5b58\uff0c\u6307\u9488\u5b58\u7684\u662f\u6307\u5411\u4e00\u5757\u5185\u5b58\u7684\u5730\u5740\u3002\u6307\u9488\u5206\u914d\u5185\u5b58\u7a7a\u95f4\uff0c\u5141\u8bb8\u5bf9\u6307\u9488\u7684\u8d4b\u503c\u548c\u62f7\u8d1d\uff0c\u6307\u9488\u5728\u5b9a\u4e49\u7684\u65f6\u5019\u4e0d\u9700\u8981\u521d\u59cb\u5316\uff08\u5efa\u8bae\u521d\u59cb\u5316\uff09<\/li>\n<\/ol>\n
    int<\/span> a =<\/span> 20<\/span>;<\/span>\/\/\u58f0\u660e\u4e00\u4e2a\u5b9e\u9645\u53d8\u91cf<\/span>\nint<\/span> *<\/span>p;<\/span>\/\/\u58f0\u660e\u4e00\u4e2a\u6307\u9488\u53d8\u91cf<\/span>\np =<\/span> &<\/span>a;<\/span>\/\/\u628a\u53d8\u91cf\u7684\u5730\u5740\u8d4b\u7ed9\u6307\u9488\uff0c\u5c31\u662f\u5728\u6307\u9488\u53d8\u91cf\u4e2d\u5b58\u50a8a\u7684\u5730\u5740<\/span>\ncout <<<\/span> p <<<\/span> endl;<\/span>\/\/\u8f93\u51fa\u6307\u9488\u53d8\u91cf\u4e2d\u5b58\u50a8\u7684\u5730\u5740<\/span>\ncout <<<\/span> *<\/span>p <<<\/span> endl;<\/span>\/\/\u8bbf\u95ee\u6307\u9488\u53d8\u91cf\u4e2d\u5730\u5740\u6307\u5411\u7684\u503c\uff0c\u8fd9\u91cc\u5c31\u662f20<\/span>\n\n<\/code><\/pre>\n

    \u7ed9\u6307\u9488\u8d4bNULL\u662f\u4e00\u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\uff0cint *a = NULL<\/p>\n

      \n
    1. p++\u6307\u9488\u7684\u9012\u589e\u662f\u6307\u5411\u4e0b\u4e00\u4e2a\u5185\u5b58\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u662fint\u578b\u4e0b\u4e00\u4e2a\u5c31\u662f\u79fb\u52a84\u4e2a\u4f4d\u7f6e\uff0c\u5982\u679c\u662fchar\u578b\uff0c\u4e0b\u4e00\u4e2a\u5c31\u662f\u79fb\u52a81\u4e2a\uff0c<\/li>\n
    2. \u591a\u7ea7\u95f4\u63a5\u5bfb\u5740\uff0c\u6307\u5411\u6307\u9488\u7684\u6307\u9488\uff0c**<\/li>\n
    3. \u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\uff0c\u6570\u7ec4a[],*(a+4)\u662f\u4e00\u4e2a\u8bbf\u95eea[4]\u7684\u5408\u6cd5\u65b9\u5f0f<\/li>\n
    4. sizeof\u6307\u9488\u201d\u5f97\u5230\u7684\u662f\u6307\u9488\u672c\u8eab\u7684\u5927\u5c0f\uff0c\u800c\u201dsizeof\u5f15\u7528\u201d\u5f97\u5230\u7684\u662f\u6240\u6307\u5411\u7684\u53d8\u91cf\u7684\u5927\u5c0f<\/li>\n
    5. 32\u4f4d\u7cfb\u7edf\u7684\u6307\u9488\u662f4\u5b57\u8282\uff0c64\u4f4d\u7684\u662f8\u5b57\u8282<\/li>\n<\/ol>\n

      \u5f15\u7528<\/strong><\/p>\n

        \n
      1. \u5f15\u7528\u662f\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u5bf9\u8c61\u8d77\u4e86\u4e00\u4e2a\u5c0f\u540d<\/mark>\uff08\u4e5f\u5c31\u662f\u8ddf\u539f\u6765\u7684\u5bf9\u8c61\u5c31\u662f\u4e00\u4e2a\u4e1c\u897f\uff09\uff0c\u5fc5\u987b\u88ab\u521d\u59cb\u5316<\/mark>\uff0c\u5b9a\u4e49\u5f15\u7528\u7684\u65f6\u5019\uff0c\u5c31\u662f\u5c06\u5f15\u7528\u548c\u521d\u59cb\u503c\u7ed1\u5b9a\u5728\u4e00\u8d77\uff0c\u4e00\u76f4\u7ed1\u5b9a\uff0c\u800c\u4e0d\u662f\u62f7\u8d1d\u7ed9\u5f15\u7528\uff0c\u6240\u4ee5\u5bf9\u5f15\u7528\u7684\u64cd\u4f5c\u90fd\u662f\u5728\u7ed1\u5b9a\u7684\u5bf9\u8c61\u4e0a\u8fdb\u884c\u7684\uff0c\uff08\u5f15\u7528\u672c\u8eab\u4e0d\u662f\u5bf9\u8c61\uff0c\u6240\u4ee5\u5f15\u7528\u4e0d\u80fd\u518d\u88ab\u5f15\u7528\u4e86\uff09\uff0c\u6240\u4ee5\u5f15\u7528\u5728\u521d\u59cb\u5316\u540e\u5c31\u4e0d\u80fd\u518d\u88ab\u6539\u53d8\u4e86\uff0c\u6307\u9488\u53ef\u4ee5\u6539\u53d8\uff0c\u53ef\u4ee5\u5148\u540e\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61<\/li>\n
      2. \u56e0\u4e3a\u5f15\u7528\u4e0d\u662f\u65b0\u521b\u5efa\u7684\u5bf9\u8c61\uff0c\u6240\u4ee5\u5f15\u7528\u4e0d\u5206\u914d\u5b58\u50a8\u7a7a\u95f4<\/mark>\uff0c\u6307\u9488\u5982\u679c\u521d\u59cb\u5316\u9700\u8981\u5206\u914d\u5b58\u50a8\u7a7a\u95f4<\/li>\n
      3. \u5f15\u7528\u4e0e\u6307\u9488\u7684\u533a\u522b\uff0c\u6307\u9488\u7684\u503c\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u4f46\u662f\u5f15\u7528\u7684\u503c\u4e0d\u80fd\u4e3aNULL<\/mark>\uff0c\u4e0d\u5b58\u5728\u7a7a\u5f15\u7528\uff1b\u4e00\u65e6\u88ab\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u5c31\u4e0d\u80fd\u6307\u5411\u53e6\u4e00\u4e2a\uff1b\u5f15\u7528\u5fc5\u987b\u5728\u521b\u5efa\u65f6\u88ab\u521d\u59cb\u5316<\/li>\n
      4. \u5f15\u7528\u4f7f\u7528\u65f6\u65e0\u9700\u89e3\u5f15\u7528\uff0c\u6307\u9488\u9700\u89e3\u5f15\u7528<\/li>\n
      5. \u5f15\u7528\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\uff0c\u662f\u5b9e\u53c2\u7684\u5c0f\u540d\uff0c\u5982\u679c\u4e0d\u6539\u53d8\u53d8\u91cf\u7684\u503c\uff0c\u901a\u5e38\u91c7\u7528\u5e38\u5f15\u7528\u4f20\u53c2<\/li>\n
      6. \u5bf9\u5f15\u7528\u81ea\u589e\u81ea\u51cf\u662f\u5f15\u7528\u4ee3\u8868\u7684\u5bf9\u8c61\u7684\u503c\u53d1\u751f\u53d8\u5316\uff0c\u5bf9\u6307\u9488\u81ea\u589e\u81ea\u51cf\u662f\u6307\u9488\u6307\u5411\u7684\u4f4d\u7f6e\u53d1\u751f\u53d8\u5316
        \u8d4b\u503c\u6c38\u8fdc\u6539\u53d8\u7684\u662f\u7b49\u53f7\u5de6\u4fa7\u7684\u5bf9\u8c61<\/li>\n<\/ol>\n
        int<\/span> i =<\/span> 42<\/span>;<\/span>\nint<\/span> &<\/span>r =<\/span> i;<\/span>\/\/r\u662f\u4e00\u4e2a\u5f15\u7528\uff0c\u662fi\u7684\u5c0f\u540d<\/span>\nint<\/span> *<\/span>p;<\/span>\/\/p\u662f\u4e00\u4e2a\u6307\u9488<\/span>\nint<\/span> *<\/span>p1 =<\/span> nullptr<\/span>;<\/span>\/\/\u5b9a\u4e49p1\u662f\u4e00\u4e2a\u7a7a\u6307\u9488<\/span>\nint<\/span> *<\/span>p2 =<\/span> &<\/span>i;<\/span>\/\/\u8fd9\u91cc\u7684&\u5728\u7b49\u53f7\u53f3\u8fb9\u662f\u53d6\u5730\u5740\u7b26\uff0c\u6307\u9488p2\u5b58\u653e\u7684\u662fi\u7684\u5730\u5740<\/span>\n*<\/span>p2 =<\/span> 0<\/span>;<\/span>\/\/\u8fd9\u91cc\u7684*\u662f\u89e3\u5f15\u7528\u7b26\u53f7\uff0c\u5f97\u5230\u6307\u9488p2\u6240\u6307\u7684\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u7ecfp2\u7ed9i\u8d4b\u503c\uff0c\u89e3\u5f15\u7528\u64cd\u4f5c\u4ec5\u9002\u7528\u4e8e\u6307\u5411\u4e86\u67d0\u4e2a\u5bf9\u8c61\u7684\u6709\u6548\u6307\u9488<\/span>\np1 =<\/span> &<\/span>adc\uff1b\/\/p1\u7684\u503c\u88ab\u6539\u53d8\uff0c\u73b0\u5728pi\u6307\u5411adc<\/span>\n*<\/span>p1 =<\/span> 0<\/span>\uff1b\/\/*p1\u88ab\u6539\u53d8\uff0c\u4e5f\u5c31\u662f\u6307\u9488pi\u6307\u5411\u7684\u90a3\u4e2a\u5bf9\u8c61\u53d1\u751f\u6539\u53d8<\/span>\n<\/code><\/pre>\n

        \u51fd\u6570\u5f15\u7528\u4f20\u53c2<\/strong>
        \u5f15\u7528\u548c\u539f\u59cb\u53d8\u91cf\u90fd\u6307\u5411\u540c\u4e00\u4e2a\u5730\u5740\uff0c\u56e0\u6b64\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u4e2d\u5b58\u50a8\u7684\u53d8\u91cf\u503c\uff0c\u4fee\u6539\u5f15\u7528\u5c31\u662f\u4fee\u6539\u539f\u59cb\u503c\uff1b\u6240\u4ee5\u53ef\u4ee5\u7528\u4e8e\u51fd\u6570\u4f20\u9012\u53c2\u6570\u6216\u51fd\u6570\u8fd4\u56de\u503c<\/mark><\/p>\n

        \u51fd\u6570\u5f15\u7528\u4f20\u53c2\uff0c\u5c06\u51fd\u6570\u7684\u5f62\u53c2\u6307\u5b9a\u4e3a\u5f15\u7528\uff0c\u8c03\u7528\u65f6\u5c31\u662f\u628a\u5b9e\u53c2\u76f4\u63a5\u4f20\u9012\u7ed9\u5f62\u53c2\uff0c\u800c\u4e0d\u662f\u62f7\u8d1d\u7ed9\u5f62\u53c2\uff0c\u6240\u4ee5\u5728\u51fd\u6570\u4f53\u4e2d\u4fee\u6539\u4e86\u5f62\u53c2\uff0c\u5b9e\u53c2\u4e5f\u4f1a\u88ab\u4fee\u6539
        \uff08\u8865\u5145\u4e00\u70b9\uff1a\u503c\u4f20\u9012\u53ea\u662f\u7b80\u5355\u7684\u62f7\u8d1d<\/mark>\uff0c\u4e0d\u4f1a\u5b9e\u73b0\u4ea4\u6362\u4e24\u6570\u7684\u76ee\u7684\uff0c\u56e0\u4e3a\u4f20\u8fdb\u53bb\u7684\u662f\u5b9e\u53c2\u653e\u7684\u526f\u672c\uff08\u526f\u672c\u5565\u610f\u601d\uff0c\u5c31\u662f\u628a\u5b9e\u53c2\u7684\u503c\u62f7\u8d1d\u4e00\u4efd\u7136\u540e\u4f20\u8fdb\u53bb\uff09\uff0c\u5728\u4ea4\u6362\u51fd\u6570\u5185\u90e8\u6267\u884c\u7684\u662f\u5f62\u53c2\u7684\u6539\u53d8\uff0c\u5f62\u53c2\u7684\u6539\u53d8\u4e0d\u4f1a\u5f71\u54cd\u539f\u6765\u7684\u5b9e\u53c2\uff09<\/p>\n

        swap<\/span>(<\/span>num1,<\/span> num2)<\/span>;<\/span>\/\/\u5f15\u7528\u4f20\u9012<\/span>\nvoid<\/span> swap<\/span>(<\/span>int<\/span> &<\/span>a,<\/span> int<\/span> &<\/span>b)<\/span>{ \n   <\/span>\n    int<\/span> temp =<\/span> a;<\/span>\n    a =<\/span> b;<\/span>\n    b =<\/span> temp;<\/span>}<\/span>\n\/\/\u8fd9\u79cd\u65b9\u5f0f\u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u4e0b\u9762\u8fd9\u4e2a\u4f20\u7684\u662f\u5730\u5740<\/span>\nswap<\/span>(<\/span>&<\/span>num1,<\/span> &<\/span>num2)<\/span>;<\/span>\nvoid<\/span> swap<\/span>(<\/span>int<\/span> *<\/span>a,<\/span> int<\/span> *<\/span>b)<\/span>{ \n   <\/span>\n    int<\/span> temp =<\/span> *<\/span>a;<\/span>\/\/\u8fd9\u91cc\u5c3d\u91cf\u4e0d\u8981\u628atemp\u4f5c\u4e3a\u6307\u9488\uff0c\u56e0\u4e3a\u6ca1\u6709\u521d\u59cb\u5316\u5f88\u5371\u9669\uff0c\u5f53\u7136\u4f60\u521d\u59cb\u5316\u4e86\u5c31\u662f\u53ef\u4ee5<\/span>\n    *<\/span>a =<\/span> *<\/span>b;<\/span>\n    *<\/span>b =<\/span> temp;<\/span>}<\/span>\n<\/code><\/pre>\n

        \u6b64\u6587\u5173\u4e8e\u5404\u79cd\u4f20\u9012\u6bd4\u8f83\u6b63\u786ehttps:\/\/www.cnblogs.com\/chen-kh\/p\/6696305.html
        \u5e38\u5f15\u7528\uff1a\u4e0d\u5e0c\u671b\u901a\u8fc7\u5f15\u7528\u6765\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u7684\u503c
        const int &b = a;<\/p>\n

        \u7eb8\u4e0a\u5f97\u6765\u7ec8\u89c9\u6d45\uff0c\u7edd\u77e5\u6b64\u4e8b\u8981\u8eac\u884c<\/strong>\uff0c\u6307\u9488\u603b\u662f\u6307\u6765\u6307\u53bb\uff0c\u8fd8\u662f\u4e0a\u673a\u770b\u4e0b\u5230\u5e95\u600e\u4e48\u6307<\/p>\n

        #include<\/span> <iostream><\/span><\/span>\nusing<\/span> namespace<\/span> std;<\/span>\n\nint<\/span> main<\/span>(<\/span>)<\/span>\n{ \n   <\/span>\n\tint<\/span> a[<\/span>5<\/span>]<\/span> =<\/span> { \n   <\/span>1<\/span>,<\/span>3<\/span>,<\/span>4<\/span>,<\/span>6<\/span>,<\/span>5<\/span>}<\/span>;<\/span>\n\tint<\/span> *<\/span>p =<\/span> a;<\/span>\n\tcout <<<\/span> p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a0x7ffeefbffde0<\/span>\n\tcout <<<\/span>*<\/span>p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a1,\u56e0\u4e3a\u6570\u7ec4\u540da\u76f8\u5f53\u4e8e\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20<\/span>\n\tp++<\/span>;<\/span>\n\tcout <<<\/span> p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a0x7ffeefbffde4\uff0c\u6ce8\u610f\u6bd4\u521a\u521a\u7684\u589e\u52a04\uff0c\u56e0\u4e3a\u4e00\u4e2aint \u662f4\uff0c\u5730\u5740\u867d\u7136\u6267\u884c\u7684\u662f+1\uff0c\u5b9e\u9645\u662f+4<\/span>\n\tcout <<<\/span> *<\/span>p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a3\uff0c\uff0c\u81ea\u7136\u5c31\u662f\u7b2c\u4e8c\u4e2a\u5143\u7d20\uff0c\u56e0\u4e3a\u5730\u5740\u53d8\u4e86<\/span>\n\t*<\/span>p++<\/span>;<\/span>\/\/\u6267\u884c\u5b8c\u8fd9\u4e2a\u8bed\u53e5\uff0c*p\u5411\u4e0b\u6307\u4e00\u4f4d<\/span>\n\tcout <<<\/span> p<<<\/span>endl;<\/span>\/\/\u6240\u4ee5\u7ed3\u679c\u4e3a0x7ffeefbffde8\uff0c\u5730\u5740\u53c8\u589e\u52a0\u4e864<\/span>\n\tcout <<<\/span> *<\/span>p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a4\uff0c\u6307\u5411\u7684\u5185\u5bb9\u81ea\u7136\u968f\u7740\u5730\u5740\u53d8\u5316<\/span>\n\t(<\/span>*<\/span>p)<\/span>++<\/span>;<\/span>\n\tcout <<<\/span> p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a0x7ffeefbffde8\u3002\u5730\u5740\u6ca1\u53d8\uff0c\u52a0\u7684\u53ea\u662f\u6307\u5411\u5bf9\u8c61\u7684\u503c<\/span>\n\tcout <<<\/span> *<\/span>p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a5\uff0c\u8fd9\u91cc\u662f\u521a\u521a\u76844+1<\/span>\n\t*<\/span>(<\/span>p++<\/span>)<\/span>;<\/span>\n\tcout <<<\/span> p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a0x7ffeefbffdec\uff0c\u5730\u5740\u53c8\u589e\u52a0\u4e86<\/span>\n\tcout <<<\/span> *<\/span>p<<<\/span>endl;<\/span>\/\/\u7ed3\u679c\u4e3a6\uff0c\u6307\u5411\u7684\u5185\u5bb9\u53d8\u5316\u4e86<\/span>\n   return<\/span> 0<\/span>;<\/span>\n}<\/span>\n<\/code><\/pre>\n

        \u6211\u60f3\u901a\u8fc7\u535a\u5ba2\u5e2e\u52a9\u548c\u6211\u4e00\u6837\u6709\u56f0\u60d1\u7684\u5c0f\u4f19\u4f34\uff0c\u770b\u5b8c\u6b64\u6587\u4f60\u61c2\u4e86\u5417\uff0c\u6b22\u8fce\u4e00\u8d77\u4ea4\u6d41\uff0c\u535a\u5ba2\u4ec5\u4e3a\u6211\u4e2a\u4eba\u7684\u5b66\u4e60\u7b14\u8bb0\uff0c\u5982\u6709\u9519\u8bef\uff0c\u6b22\u8fce\u6307\u6b63<\/p>\n","protected":false},"excerpt":{"rendered":"\u6307\u9488\u548c\u5f15\u7528\u8be6\u89e3---\u57fa\u7840\u7bc7#includeusingnamespacestd;intmain(){inta[5]={1,2,3,4,5};int*p=a;coutpendl;cout*pendl;p++;coutp...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6136"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6136"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6136\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}