本節詳細介紹c++中使用的數據結構。在c++中,數據類型用於聲明變量。這告訴編譯器與變量相關的數據的類型和大小。例如,
收入= 90000;
這裏income是一個int類型的變量,根據機器大小,它可以在2字節或4字節的範圍內存儲值。c++有7種基本的係統定義數據類型,如下表所示
讓我們深入了解每種數據類型
int表示整數。它的大小取決於機器,通常是4個字節(值可以在-2147483648到2147483647之間)。如。
Int roll_no = 11;
c++float and double float and double are system's containers to store floating-point numbers which are usually decimals and exponentials. The size of float is generally 4 bytes and the size of double is 8 bytes. For e.g.
浮動百分比= 93.74;
double volumeOfSphere = 251.64534;
雙倍距離= 3E21;
c++char Keyword char is used for storing characters. It can hold 1 byte. C++ characters are enclosed inside single quotes ' '. For e.g.
char性別= 'M';
c++wchar_t Wide character wchar_t is char data type with size 2 bytes instead of 1. It is used to represent non-ANSI (Unicode characters) that require more memory to represent them than a single char. IT is usually represented by appending L in in front of the value. C++11 revision also included char16_t and char32_t. For example,
wchar_t inputChar = L'ם' //存儲希伯來語字符;
c++ bool bool數據類型用於存儲具有二進製值的變量,即True或False或On或OFF。IT應用於條件語句和循環。例如,
bool condFlag = true;
void關鍵字表示給定的對象沒有數據。意思是“沒有價值”。我們在函數和指針中使用它。請注意,void不能用於聲明變量。
我們可以使用4個修飾符來修改char, int和double數據類型,即signed unsigned, short和long。下表列出了c++中帶有修飾符的內部數據類型。