Thứ Ba, 1 tháng 12, 2015

02 Data types(Các kiểu dữ liệu)

#include <iostream>
using namespace std;

int main()
{
    //data integer
    int a;
    //data char
    char grade;
    //data float
    float b;
    cout<<"Input a: ";
    cin>> a;
    cout<<"Input the grade: ";
    cin>> grade;
    cout<<"Input b: ";
    cin>> b;
    cout<<"The value inside is: "<< a<<endl;
    cout<<"The grade is: "<< grade<<endl;
    cout<<"The value inside is: "<< b;
    return 0;
}

Phân tích:
Theo (Wiki) có 4 kiểu cơ bản của các biến trong C; đó là: charintdouble và float.
Tên kiểuÝ nghĩa
charĐơn vị cơ bản nhất có thể địa chỉ hóa được; nó là một byte. Đây là một kiểu nguyên.
intLoại số nguyên theo kích cỡ tự nhiên nhất của các máy tính. Thông thường nó có thể lấy trọn một khoảng có thể địa chỉ hoá được của một word với độ lớn biến thiên từ 16, 32, hay 64 bit tùy theo kiến trúc của CPU và hệ điều hành.
floatMột giá trị dấu chấm động có độ chính xác đơn.
doubleMột giá trị dấu chấm động có độ chính xác kép.

-----cin>> //nhập vào giống scanf("")
Data types:
1.char is 1 bytes
2.double is 8 bytes
3.short int is 2 bytes
4.{ } Is using the beginning and end of block command({ } là sử dụng mở đầu và kết thúc của khối lệnh) 
5. ; ends most lines of C++ code(; kết thúc hầu hết các dòng code C++)
Phần xem thêm:
The following table tells you the basic data types in C++
TypeKeyword
Booleanbool
Characterchar
Integerint
Floating pointfloat
Double floating pointdouble
Valuelessvoid
Wide characterwchar_t
This modifiers can be used on data types for the size differentiation of particular data type
  • signed
  • unsigned
  • short
  • long
The following table shows the data type size.
TypeTypical Bit WidthTypical Range
char1byte-127 to 127 or 0 to 255
unsigned char1byte0 to 255
signed char1byte-127 to 127
int4bytes-2147483648 to 2147483647
unsigned int4bytes0 to 4294967295
signed int4bytes-2147483648 to 2147483647
short int2bytes-32768 to 32767
unsigned short intRange0 to 65,535
signed short intRange-32768 to 32767
long int4bytes-2,147,483,647 to 2,147,483,647
signed long int4bytessame as long int
unsigned long int4bytes0 to 4,294,967,295
float4bytes+/- 3.4e +/- 38 (~7 digits)
double8bytes+/- 1.7e +/- 308 (~15 digits)
long double8bytes+/- 1.7e +/- 308 (~15 digits)
wchar_t2 or 4 bytes1 wide character
This sizes may be different based upon your compiler.
004