為什麼我們在 C/C++ 中使用修飾符?


修飾符用於改變基本型別的意思,以便符合你的需要。例如,時間不能為負,將其變為無符號數是有意義的。C++ 允許在 char、int 和 double 資料型別之前使用修飾符。資料型別修飾符如下所示 -

  • signed
  • unsigned
  • long
  • short

修飾符 signed、unsigned、long 和 short 可以應用於整數基本型別。此外,signed 和 unsigned 可以應用於 char,long 可以應用於 double。

修飾符 signed 和 unsigned 也可用作 long 或 short 修飾符的字首。例如,unsigned long int。

C++ 允許使用簡寫表示來宣告無符號、短或長整數。你只需使用單詞 unsigned、short 或 long,而不用 int。int 是隱含的。例如 -

unsigned long a; // AND
unsigned long int a; // Are the same

更新於: 2020 年 2 月 26 日

268 次瀏覽

開啟您的事業

完成課程,獲得認證

開始吧
廣告
© . All rights reserved.