• <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>

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            c/c++面試試題轉載

             

            1. 以下三條輸出語句分別輸出什么?[C]
            char str1[]       = "abc";
            char str2[]       = "abc";
            const char str3[] = "abc";
            const char str4[] = "abc";
            const char* str5  = "abc";
            const char* str6  = "abc";
            cout << boolalpha << ( str1==str2 ) << endl; //
            輸出什么?
            cout << boolalpha << ( str3==str4 ) << endl; //
            輸出什么?
            cout << boolalpha << ( str5==str6 ) << endl; //
            輸出什么?

            13.
            C++內建型別 A B,在哪幾種情況下B能隱式轉化為A[C++中等]
            答:
            a. class B : public A { ……} // B
            公有繼承自A,可以是間接繼承的
            b. class B { operator A( ); } // B
            實現了隱式轉化為A的轉化
            c. class A { A( const B& ); } // A
            實現了non-explicit的參數為B(可以有其他帶默認值的參數)構造函數
            d. A& operator= ( const A& ); //
            賦值操作,雖不是正宗的隱式類型轉換,但也可以勉強算一個

            12.
            以下代碼中的兩個sizeof用法有問題嗎?[C]
            void UpperCase( char str[] ) //
            str 中的小寫字母轉換成大寫字母
            {
                for( size_t i=0; i<sizeof(str)/sizeof(str[0]); ++i )
                    if( 'a'<=str[i] && str[i]<='z' )
                        str[i] -= ('a'-'A' );
            }
            char str[] = "aBcDe";
            cout << "str
            字符長度為: " << sizeof(str)/sizeof(str[0]) << endl;
            UpperCase( str );
            cout << str << endl;

            7.
            以下代碼有什么問題?[C]
            void char2Hex( char c ) //
            將字符以16進制表示
            {
                char ch = c/0x10 + '0'; if( ch > '9' ) ch += ('A'-'9'-1);
                char cl = c%0x10 + '0'; if( cl > '9' ) cl += ('A'-'9'-1);
                cout << ch << cl << ' ';
            }
            char str[] = "I love
            中國";
            for( size_t i=0; i<strlen(str); ++i )
                char2Hex( str[i] );
            cout << endl;

            4.
            以下代碼有什么問題?[C++]
            struct Test
            {
                Test( int ) {}
                Test() {}
                void fun() {}
            };
            void main( void )
            {
                Test a(1);
                a.fun();
                Test b();
                b.fun();
            }

            5.
            以下代碼有什么問題?[C++]
            cout << (true?1:"1") << endl;

            8.
            以下代碼能夠編譯通過嗎,為什么?[C++]
            unsigned int const size1 = 2;
            char str1[ size1 ];
            unsigned int temp = 0;
            cin >> temp;
            unsigned int const size2 = temp;
            char str2[ size2 ];

            9.
            以下代碼中的輸出語句輸出0嗎,為什么?[C++]
            struct CLS
            {
                int m_i;
                CLS( int i ) : m_i(i) {}
                CLS()
                {
                    CLS(0);
                }
            };
            CLS obj;
            cout << obj.m_i << endl;

            10. C++
            中的空類,默認產生哪些類成員函數?[C++]
            答:
            class Empty
            {
            public:
                Empty();                          //
            缺省構造函數
                Empty( const Empty& );            //
            拷貝構造函數
                ~Empty();                         //
            析構函數
                Empty& operator=( const Empty& ); //
            賦值運算符
                Empty* operator&();               //
            取址運算符
                const Empty* operator&() const;   //
            取址運算符 const
            };

            3.
            以下兩條輸出語句分別輸出什么?[C++]
            float a = 1.0f;
            cout << (int)a << endl;
            cout << (int&)a << endl;
            cout << boolalpha << ( (int)a == (int&)a ) << endl; //
            輸出什么?
            float b = 0.0f;
            cout << (int)b << endl;
            cout << (int&)b << endl;
            cout << boolalpha << ( (int)b == (int&)b ) << endl; //
            輸出什么?

            2.
            以下反向遍歷array數組的方法有什么錯誤?[STL]
            vector array;
            array.push_back( 1 );
            array.push_back( 2 );
            array.push_back( 3 );
            for( vector::size_type i=array.size()-1; i>=0; --i ) //
            反向遍歷array數組
            {
                cout << array[i] << endl;
            }

            6.
            以下代碼有什么問題?[STL]
            typedef vector IntArray;
            IntArray array;
            array.push_back( 1 );
            array.push_back( 2 );
            array.push_back( 2 );
            array.push_back( 3 );
            //
            刪除array數組中所有的2
            for( IntArray::iterator itor=array.begin(); itor!=array.end(); ++itor )
            {
                if( 2 == *itor ) array.erase( itor );
            }

            11.
            寫一個函數,完成內存之間的拷貝。[考慮問題是否全面]
            答:
            void* mymemcpy( void *dest, const void *src, size_t count )
            {
                char* pdest = static_cast<char*>( dest );
                const char* psrc = static_cast<const char*>( src );
                if( pdest>psrc && pdest<psrc+cout )
            能考慮到這種情況就行了
                {
                    for( size_t i=count-1; i!=-1; --i )
                            pdest[i] = psrc[i];
                }
                else
                {
                    for( size_t i=0; i<count; ++i )
                        pdest[i] = psrc[i];
                }
                return dest;
            }
            int main( void )
            {
                char str[] = "0123456789";
                mymemcpy( str+1, str+0, 9 );
                cout << str << endl;

                system( "Pause" );
                return 0;
            }

            posted on 2005-12-24 19:32 夢在天涯 閱讀(2724) 評論(1)  編輯 收藏 引用 所屬分類: CPlusPlus

            評論

            # re: c/c++面試試題轉載 2008-07-06 00:42 追風少年

            一看下一跳,原來自己基礎還是不怎么的。
            看樣子還得務實點。  回復  更多評論   

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804430
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久久久久国产精品免费无码| 国产韩国精品一区二区三区久久| 精品久久久久久无码人妻热| 久久播电影网| 日本精品久久久久久久久免费| 午夜精品久久久久久毛片| 亚洲乱亚洲乱淫久久| 久久人人爽人人爽人人AV| 国产精品日韩欧美久久综合| 久久精品亚洲中文字幕无码麻豆| 久久久久亚洲AV无码永不| 久久无码一区二区三区少妇| 精品精品国产自在久久高清| 欧美熟妇另类久久久久久不卡| 国产视频久久| 国产精品美女久久久久久2018| 久久精品国产亚洲AV嫖农村妇女| 99热精品久久只有精品| 亚洲精品无码久久久影院相关影片 | 人妻少妇精品久久| 久久综合给合久久狠狠狠97色| 精品久久久无码中文字幕天天| 国产精品毛片久久久久久久| 欧美精品国产综合久久| 久久91精品国产91久| 国内精品久久久久久久亚洲| 久久66热人妻偷产精品9| 久久免费看黄a级毛片| 无码人妻久久久一区二区三区| 麻豆久久| 亚州日韩精品专区久久久| 99久久精品免费看国产一区二区三区| 99久久人妻无码精品系列蜜桃| 午夜精品久久久久久毛片| 久久午夜无码鲁丝片| 色88久久久久高潮综合影院 | 久久久一本精品99久久精品88| 漂亮人妻被中出中文字幕久久| 亚洲国产成人久久笫一页| 亚洲av成人无码久久精品 | 久久无码AV中文出轨人妻|