• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            void main() { }

            Hello ,world !

            常用鏈接

            統計

            最新評論

            談談: 常量指針與指針常量(const Type* and Type* const )

              常量指針,“常量的指針”,它(指針)指向常量,而本身(即其地址)非常量。
              指針常量,“指針的常量”,它(指針)本身是常量 ,而指向的東西并非常量。
            呼呼 ... 說的還不是很清楚哦 ,是吧。還就來看看代碼吧 !

             

            #include <iostream>
            #include 
            <string>

            using namespace std;
            int main(int argc,char* argv[])
            {
            //  ---- test const ptr and ptr const 常量指針與指針常量   
                const   char    c = 'a' ;
                cout 
            << "const   char    c = 'a' ,c : " << c << endl ;
                
            char    *pchar = const_cast<char*>(&c) ;
                
            *pchar = 'A' ;
                
            //c = 'A' ;
                cout << "*pchar(c) = 'A' ; ,c : " << c << endl ;
                cout 
            << "*pchar(c) = 'A' ; ,*pchar : " << *pchar  << endl ;
                
            const   char*   const_ptr = "const_ptr" ;  //常量指針 -- 指針所指的值不能改變
                char    temp[] = "ptr_const" ;
                
            char* const   ptr_const = temp ; // 指針常量 -- 指針的值(即地址)不能改變
                const_ptr = "Const_ptr" ;       // --OK !
            //    const_ptr[0] = 'C' ; //but error ,[C++ Error]  E2024 Cannot modify a const object
                ptr_const[0= 'P' ; // --- OK !
            //    ptr_const = "Ptr_const" ; //but error ,[C++ Error]  E2024 Cannot modify a const object
                cout << "const_ptr :" << const_ptr <<endl  ;

                cout 
            << "ptr_const :" << ptr_const << endl  ;
                
            string  str = "String" ;
                cout 
            << str << endl ;
                const_ptr 
            = str.c_str() ;
                
            //const_ptr[0] = 's' ;  //error--Cannot modify a const object
                cout << const_ptr << endl ; // --- 
                str[0= 's' ; // change OK --- 
                cout << const_ptr << endl ; // --- 間接更改 ---
            /************************************************************/
                cout 
            << "\n\n\n\n       Hello ,World !" <<endl ;
                system(
            "pause");
                
            return 0;
            }


            輸出結果:
            const   char    c = 'a' ,c : a
            *pchar(c) = 'A' ; ,c : a
            *pchar(c) = 'A' ; ,*pchar : A
            const_ptr :Const_ptr
            ptr_const :Ptr_const
            String
            String
            string

             


                   Hello ,World !
            請按任意鍵繼續. . .

            還有一點: “常量指針常量” --- const Type* const Ptr ;// Ptr 即以上所述二者之合 。
            若是你有過疑惑,那就上機試試揣摩一下,就會搞定的 !
             

             


             

             

             



             

            posted on 2009-07-09 22:31 only 閱讀(393) 評論(0)  編輯 收藏 引用

            狠狠色丁香久久婷婷综合蜜芽五月| 中文字幕精品久久| 国产精品久久久久9999高清| 久久香蕉国产线看观看99| 欧美成a人片免费看久久| 亚洲AV无码久久精品色欲| 日本福利片国产午夜久久| 伊人色综合久久天天网| 久久国产精品99久久久久久老狼| 久久久噜噜噜久久| 久久久国产精品网站| 久久久久久久波多野结衣高潮| 美女写真久久影院| 久久精品人人做人人妻人人玩| 久久久久亚洲AV无码专区桃色| 72种姿势欧美久久久久大黄蕉| 亚洲精品乱码久久久久久蜜桃| 色综合合久久天天综合绕视看| 伊人久久无码中文字幕| 色偷偷88欧美精品久久久| 色成年激情久久综合| 久久99精品国产麻豆| 欧美精品国产综合久久| 欧美精品一区二区久久| 韩国三级中文字幕hd久久精品| 99久久99这里只有免费的精品| 亚洲日本va中文字幕久久| 久久只有这里有精品4| 亚洲&#228;v永久无码精品天堂久久| 久久综合狠狠色综合伊人| 97久久精品人妻人人搡人人玩 | 精品午夜久久福利大片| 久久综合九色综合欧美就去吻 | 久久中文字幕精品| 2021最新久久久视精品爱| 免费久久人人爽人人爽av| 久久精品无码一区二区日韩AV| 久久99热只有频精品8| 精品国产99久久久久久麻豆| 亚洲va久久久噜噜噜久久天堂| 婷婷伊人久久大香线蕉AV|