c++資料類型–文字常量、變數

來源:互聯網
上載者:User

文字常量

整數型別:char, short, int, long
int i = 100; //預設為int
int i = 100u; //無符號整型
int i = 100L; //long型
int i = 100UL; //無符號long型

表示方式:10進位, 八進位, 16進位
int i = 20;       //10
int i = 020;     //8
int i = 0x20;   //16

浮點型:單精確度(float)、雙精確度(double)、擴充精度(long double)
float f = 2.0;       //預設double
float f = 2.0F;      //float
float f = 2.0L;     //long double

注意,以下寫法是正確的:
2.0  2.   2.0F   2.0L   0.0
以下寫法是不正確的:
2F

科學計數:3.14e+2   指3.14小數點向右移2位,314.000000
                  3.14e-2   指3.14小數點向左移2位,0.031400
                  3.14e1(3.14e1L) 指3.14小數點向右移1位,31.400000

逸出字元
逸出字元格式通常為 /000 , 表示3個8進位數組成的序列。
/144    /064    /0   都表示8進位數

字元,字串
"abc" 字串後面會加上0 ('/0'), 為字串結束標誌

"aaaaaa /
bbbbbbb"    字串換行可以加續行符 /

文字變數

int ival = ival;    //標識符在定義出現後,馬上是可見的,但這樣做不明智

int ival = int();  //這種寫法合法,被初始化為0, double d = double();  被初始化為0.0

如果引用一個外部定義的變數 extern int i;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.