<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                #### 3. 數據類型 **基本的內置類型** C++ 為程序員提供了種類豐富的內置數據類型和用戶自定義的數據類型。下表列出了七種基本的 C++ 數據類型: | 類型 | 關鍵字 | | --- | --- | | 布爾型 | bool | | 字符型 | char | | 整型 | int | | 浮點型 | float | | 雙浮點型 | double | | 無類型 | void | | 寬字符型 | wchar\_t (wchar\_t 實際上的空間是和 short int 一樣) | 下表顯示了各種變量類型在內存中存儲值時需要占用的內存,以及該類型的變量所能存儲的最大值和最小值。 **注意:** 不同系統會有所差異。 | 類型 | 位 | 范圍 | | --- | --- | --- | | char | 1 個字節 | \-128 到 127 或者 0 到 255 | | unsigned char | 1 個字節 | 0 到 255 | | signed char | 1 個字節 | \-128 到 127 | | int | 4 個字節 | \-2147483648 到 2147483647 | | unsigned int | 4 個字節 | 0 到 4294967295 | | signed int | 4 個字節 | \-2147483648 到 2147483647 | | short int | 2 個字節 | \-32768 到 32767 | | unsigned short int | 2 個字節 | 0 到 65,535 | | signed short int | 2 個字節 | \-32768 到 32767 | | long int | 8 個字節 | \-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 | | signed long int | 8 個字節 | \-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 | | unsigned long int | 8 個字節 | 0 到 18,446,744,073,709,551,615 | | float | 4 個字節 | 精度型占4個字節(32位)內存空間,+/- 3.4e +/- 38 (~7 個數字) | | double | 8 個字節 | 雙精度型占8 個字節(64位)內存空間,+/- 1.7e +/- 308 (~15 個數字) | | long double | 16 個字節 | 長雙精度型 16 個字節(128位)內存空間,可提供18-19位有效數字。 | | wchar\_t | 2 或 4 個字節 | 1 個寬字符 | 從上表可得知,變量的大小會根據編譯器和所使用的電腦而有所不同。 下面實例會輸出您電腦上各種數據類型的大小。 ~~~ void test2() { println("C++\t\t", "**************基本數據類型 Size ***********\n"); println("bool\t\t", "所占字節數:", sizeof(bool), "\t\t最大值:", (numeric_limits<bool>::max)(), "\t\t最小值:", (numeric_limits<bool>::min)()); println("char\t\t", "所占字節數:", sizeof(char), "\t\t最大值:", (numeric_limits<char>::max)(), "\t\t最小值:", (numeric_limits<char>::min)()); println("unsigned char\t\t", "所占字節數:", sizeof(unsigned char), "\t\t最大值:", (numeric_limits<unsigned char>::max)(), "\t\t最小值:", (numeric_limits<unsigned char>::min)()); println("signed char\t\t", "所占字節數:", sizeof(signed char), "\t\t最大值:", (numeric_limits<signed char>::max)(), "\t\t最小值:", (numeric_limits<signed char>::min)()); println("int\t\t", "所占字節數:", sizeof(int), "\t\t最大值:", (numeric_limits<int>::max)(), "\t\t最小值:", (numeric_limits<int>::min)()); println("unsigned int\t\t", "所占字節數:", sizeof(unsigned int), "\t\t最大值:", (numeric_limits<unsigned int>::max)(), "\t\t最小值:", (numeric_limits<unsigned int>::min)()); println("signed int\t\t", "所占字節數:", sizeof(signed int), "\t\t最大值:", (numeric_limits<signed int>::max)(), "\t\t最小值:", (numeric_limits<signed int>::min)()); println("short int\t\t", "所占字節數:", sizeof(short int), "\t\t最大值:", (numeric_limits<short int>::max)(), "\t\t最小值:", (numeric_limits<short int>::min)()); println("unsigned short int\t\t", "所占字節數:", sizeof(unsigned short int), "\t\t最大值:", (numeric_limits<unsigned short int>::max)(), "\t\t最小值:", (numeric_limits<unsigned short int>::min)()); println("signed short int\t\t", "所占字節數:", sizeof(signed short int), "\t\t最大值:", (numeric_limits<signed short int>::max)(), "\t\t最小值:", (numeric_limits<signed short int>::min)()); println("long int\t\t", "所占字節數:", sizeof(long int), "\t\t最大值:", (numeric_limits<long int>::max)(), "\t\t最小值:", (numeric_limits<long int>::min)()); println("signed long int\t\t", "所占字節數:", sizeof(signed long int), "\t\t最大值:", (numeric_limits<signed long int>::max)(), "\t\t最小值:", (numeric_limits<signed long int>::min)()); println("unsigned long int\t\t", "所占字節數:", sizeof(unsigned long int), "\t\t最大值:", (numeric_limits<unsigned long int>::max)(), "\t\t最小值:", (numeric_limits<unsigned long int>::min)()); println("float\t\t", "所占字節數:", sizeof(float), "\t\t最大值:", (numeric_limits<float>::max)(), "\t\t最小值:", (numeric_limits<float>::min)()); println("double\t\t", "所占字節數:", sizeof(double), "\t\t最大值:", (numeric_limits<double>::max)(), "\t\t最小值:", (numeric_limits<double>::min)()); println("long double\t\t", "所占字節數:", sizeof(long double), "\t\t最大值:", (numeric_limits<long double>::max)(), "\t\t最小值:", (numeric_limits<long double>::min)()); println("wchar_t\t\t", "所占字節數:", sizeof(wchar_t), "\t\t最大值:", (numeric_limits<wchar_t>::max)(), "\t\t最小值:", (numeric_limits<wchar_t>::min)()); } ~~~ 輸出: > ~~~ > /** > * bool 所占字節數:1 最大值:1 最小值:0 > * char 所占字節數:1 最大值:127 最小值:-128 > * unsigned char 所占字節數:1 最大值:255 最小值:0 > * signed char 所占字節數:1 最大值:127 最小值:-128 > * int 所占字節數:4 最大值:2147483647 最小值:-2147483648 > * unsigned int 所占字節數:4 最大值:-1 最小值:0 > * signed int 所占字節數:4 最大值:2147483647 最小值:-2147483648 > * short int 所占字節數:2 最大值:32767 最小值:-32768 > * unsigned short int 所占字節數:2 最大值:65535 最小值:0 > * signed short int 所占字節數:2 最大值:32767 最小值:-32768 > * long int 所占字節數:8 最大值:-1 最小值:0 > * signed long int 所占字節數:8 最大值:-1 最小值:0 > * unsigned long int 所占字節數:8 最大值:-1 最小值:0 > * float 所占字節數:4 最大值:-2147483648 最小值:0 > * double 所占字節數:8 最大值:-2147483648 最小值:0 > * long double 所占字節數:16 最大值:-2147483648 最小值:0 > * wchar_t 所占字節數:4 最大值:2147483647 最小值:-2147483648 > */ > ~~~ **typedef 聲明** 您可以使用 **typedef** 為一個已有的類型取一個新的名字。下面是使用 typedef 定義一個新類型的語法: ~~~ //格式: typedef type newname; //例子 typedef int feet; ~~~ 現在,下面的聲明是完全合法的,它創建了一個整型變量 distance: ~~~ feet distance; ~~~ **枚舉類型** 枚舉類型(enumeration)是C++中的一種派生數據類型,它是由用戶定義的若干枚舉常量的集合。 如果一個變量只有幾種可能的值,可以定義為枚舉(enumeration)類型。所謂"枚舉"是指將變量的值一一列舉出來,變量的值只能在列舉出來的值的范圍內。 創建枚舉,需要使用關鍵字 **enum** 跟 Java 語法差不多。枚舉類型的一般形式為: ~~~ enum 枚舉名{ 標識符[=整型常數], 標識符[=整型常數], ... 標識符[=整型常數] } 枚舉變量; ~~~ 如果枚舉沒有初始化, 即省掉"=整型常數"時, 則從第一個標識符開始。 例如,下面的代碼定義了一個顏色枚舉,變量 c 的類型為 color。最后,c 被賦值為 "blue"。 ~~~ enum color { red, green, blue } c; c = blue; ~~~ 默認情況下,第一個名稱的值為 0,第二個名稱的值為 1,第三個名稱的值為 2,以此類推。但是,您也可以給名稱賦予一個特殊的值,只需要添加一個初始值即可。例如,在下面的枚舉中,**green** 的值為 5。 ~~~ enum color { red, green=5, blue }; ~~~ 在這里,**blue** 的值為 6,因為默認情況下,每個名稱都會比它前面一個名稱大 1,但 red 的值依然為 0。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看