Basic data types for C + +

Source: Internet
Author: User

Basic Type

The C + + language has a set of basic types that correspond to the basic storage units of a computer and some common ways to use these cells to save data:

The basic data types are as follows:

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

In addition, users can also define:

Enumeration type (enum) for a specific set of values

Type void, indicating no information

Pointer types, such as int*

Array type, e.g. char[]

Reference types, such as double&

declaring 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 than

void avoid; Wrong! The void type cannot directly define a variable.

Declare multiple names:

int a,b,c;
int *p, y;//such a structure is not conducive to reading, should try to avoid
int v[10], *pv;//such a structure is not conducive to reading, should try to avoid
  Initialize Variables

The initialization variable is in the following form:

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

int a = 0;

There is another type of initialization variable:

For example

Basic data types for C + +

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.