C/C ++ Basic Data Type

Source: Internet
Author: User

C/C ++ Basic Data Type
Basic Type

The C/C ++ language has a set of basic types, which correspond to the basic storage units of computers and some common ways to use these units to save data:

The basic data types are as follows:

Name Description Size * Range *
char Character or small integer. 1 byte Signed:-128 to 127
Unsigned: 0-255
short int(short) Short Integer. 2 bytes Signed:-32768 to 32767
Unsigned: 0-65535
int Integer. 4 bytes Signed:-2147483648 to 2147483647
Unsigned: 0-4294967295
long int(long) Long integer. 4 bytes Signed:-2147483648 to 2147483647
Unsigned: 0-4294967295
bool Boolean value. It can take one of two values: true or false. 1 byte trueOrfalse
float Floating point number. 4 bytes +/-3.4e +/-38 (~ 7 digits)
double Double precision floating point number. 8 bytes +/-1.7e +/-308 (~ 15 digits)
long double Long double precision floating point number. 8 bytes +/-1.7e +/-308 (~ 15 digits)
wchar_t Wide character. 2Or4 bytes 1 wide character

In addition, you can also define:

Enumeration type of a group of specific values (enum)

Type void, indicating no information

Pointer type, such as int *

Array type, such as char []

Reference type, such as double &

 

Declare Variables
int a;
float mynumber;
const double pi = 3.1415926;
extern int error_number;

const char * name = "blue";
const char * season[] = {"spring", "summer", "fall", "winter"};

Void cannot directly define a variable other

Void avoid; // error! A variable cannot be directly defined for the void type.

Declare multiple names:

Int a, B, c;
Int * p, y; // This structure is not conducive to reading, should be avoided as much as possible
Int v [10], * pv; // This structure is not conducive to reading, should be avoided as much as possible
  Initialize variable

The initialization variables are as follows:

type identifier = initial_value ; 

For example, initialize an integer variable to 0, for example

 

int a = 0;

There is another form of initialization variable:

 

type identifier (initial_value) ; 

For example

 

int a (0); 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.