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-2-11

649 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.