C++||變數

來源:互聯網
上載者:User

標籤:精度   single   引用   組成   was   order   特殊   代碼塊   字母   

 

C++ 定義了幾種基本類型:字元型,整型,浮點型

 

1.基本內建類型

  C++定義了一組表示整數,浮點數,單個字元的算術類型(arithmetic type) 定義了void特殊類型沒有對應的值,用作無傳回值的類型

  算術類型的儲存空間依機器而定,大小用來表述類型的二進位(bit),c++規定了每個算術類型的最小儲存空間.

c++ arithmetic type
type mean min storage space
bool bool --
char char 8bit
wchar_t wide char 16bit
short short int 16bit
int int 16bit
long long int 32bit
float single float 6 numbers
double double float 10 numbers
long double extra float 10 numbers

 

   1.2整型

  整數字元和布爾值的算術類型統稱為整型(integral type)

  字元類型包含: char and wchar_t,char make sure that have enough spacce ,can storage machine basic any value ,so that char is single byte.

  wchar_t type use for extra unicode ,but these can not show single char.

  

!addition:

  儲存具有結構的方法用塊(chunk)處理儲存,塊的位元位2的冪,通常8位的快位一個位元組(byte),32 bit or 4 bit is a word!;

  

  short ,int ,long show integral type,the different of the storage space, short is the half word, int is one word,and long has one or 2 word.

  bool show the true or false, 0 =false 1=true;

 

  1.3 signed & unsigned

  export bool,intergral can signed or unsigned, that can show the  -1,and unsigned need >=0 .

  

  char has 3 different type , it was char,signed char and unsigned char,

 

  1.4 show for integral

    在無符號中所有的位表示數值,定義類型用8位表示,unsigned取值為0-255

!addition

  把負值給unsigned對象屬於合法,結果對類型值個數符合如果把-1賦給unsigned char,那麼結果255是-1對256求模後的值

  1.5float

  float mostly show by 2word (64bit) , long double use 3or 4(96or 128 bit)

 

!addition

  suggest to include arthimetic type

    mostly use int can reduce mistake happen , in fact ,long is the same as int.

 

  1.6LITERAL CONSTANT

    內建類型存在字面值,沒有任何類型的字面值

   EINE:the rules literal

      we can use any the there of one : 10 ,8 or 16 example :

      20 //decimal

      024 //octal

      0x14 // hexadecimal

    當定義長整型,應使用大寫字母L!!!!!!!

  DREI:the rules float

    通常可以使用十進位表示浮點字面值常量,用e表示,預設的浮點數後面加上f或F表示單精確度.

 1.7 非列印字元地逸出序列

     當有些字元出現不可列印時,可以使用特殊的字元表示,c++定義了一下字元:

    分行符號 \n     水平定位字元  \t

    縱向定位字元  \v  退格符  \b

    斷行符號符  \r  進紙符  \f

    雙引號  \"

  1.8字串字面值

    字面值用雙引號擴起來的多個或零個字元表示。當需要串連時可以使用\or ""

 

 2.變數

  C++提供了特有的類型,決定變數的記憶體大小和布局,能夠儲存值的取值範圍以及可應用在該變數上的操作集,稱之為變數或對象

    左值和右-0

  LVALUE (ELL-VALUE):指派陳述式的左邊或右邊

 

  ARE-VALUE:右邊只能出現在賦值的右邊,不能出現在指派陳述式的左邊.

    EXAMPLE :]

    int units_sold = 0;

    double sales_price = 0,total_revenue=0;

 

  2.1變數名

    變數的標識符(IDENTIFIER),由字母,數字,底線組成.必須以字母或者底線組成,

    習慣:

      1.變數名為小寫字母

      2.使用協助記憶的名字

      3.包含多個詞用底線

  2.2定義對象

    定義以類型說明符(TYPE SPECIFIER)開始,以分號結束.類型說明指定與對象關聯的類型STR::STRING都是類型名字. 

    int 和double是內建類型,std::string是標準庫定義類型.

   2.3初始化

     C++提供了2種形式的變數形式

      (1):複製初始化(=)

      (2)直接初始化EMP(1024)

  2.4範圍

    區分名字不同含義的上下文為範圍(Scope),main為全域範圍,sum為局部範圍,用於語句範圍

  2.5const限定符

    對象為檔案的局部變數,

  2.6引用

    複合類型,以&來定義,再引用情況下,每一種參考型別都關聯到某一其他類型中且必須與該引用同類型的對象初始化。

  2.7typedef

    用於定義類型的同義字,以關鍵詞typedef 主要用於以下目    

      1.隱藏特定類型的實現

      2.簡化複雜定義

      3.允許一種類型用於多種目的

  2.8 枚舉

    定義enum 為可選擇的枚舉別名,在預設的情況下,第一個枚舉成員變數為1 其後每個成員+1,在一般的情況下枚舉定義的變數為常量,而且值必須是常量運算式(constant expression)

    for example :

   enum Forms(shape =1,s,s2,s3...);

  2.9 類類型

    定義類來自訂資料類型,在定義中設計介面實現.在定義變數時,使用存取修飾詞定義變數,在訪問標號作用於控制該類的代碼的成員,標號public,private可以多次 出現在代碼塊中

    structs關鍵字,對成員的作用相當雩都是public.

 

  3.0 前置處理器

    #include 用於作為c++用於前置處理器,只指示一個參數標頭檔名,內部的標頭檔保護符(header guard)用於避免多次處理內容

 

  

C++||變數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.