C++ 中有哪些不同的常量型別?


C++ 中沒有常量型別。只是你可以將 C++ 中的任何資料型別宣告為常量。如果使用 const 關鍵字將變數宣告為常量,則你無法重新賦值。

示例

#include<iostream>
using namespace std;
int main() {
   const int i = 5;
   // Now all of these operations are illegal and
   // will cause an error:
   i = 10;
   i *= 2;
   i++;
   i--;
   //...
   return 0;
}

更新於: 2020-02-11

649 次瀏覽

開啟你的 職業

完成課程以獲得認證

開始
廣告
© . All rights reserved.