C ++ concepts and learning/c ++ concept & amp; learning (2)

Source: Internet
Author: User

The previous article describes the development of the entire language [Why programming language is generated] and the content to be mastered by C ++.
This section begins to understand the most basic content of the first part: the built-in type of C ++, that is, the basic type.

Before doing so, let's leave a question: why are there similar basic types in all languages.


Bool: Used to indicate true or false

bool b_ret1 = true;bool b_ret2 = false;

 

Short/long: short is used to reduce/increase the range indicated by an integer, that is, the amount of memory occupied.
Signed/unsigned: Specifies the symbol. But it does not change the memory size.

Int (signed int)/unsigned int: an integer in the general sense. The difference between the two is that there is no symbol.
After adding short, signed, and unsigned, you can control the Integer Range. So there are multiple integers:
Int (signed int)/unsigned int
Signed short int/unsigned short int
Signed long int/unsigned long int

int age = 20;unsigned int age2 = 20;short int age3 = 20;unsigned short int small_int = 22222;unsigned long int big_number = 2222222222;

 

Char (signed char)/unsigned char: a character. It is enough to use char in programming, and the efficiency will not be affected.
This type is a bit tangled. It is intended to represent characters, but it is often used to store data in its array. When it comes to pointers, let's talk about it in detail.

char letter_char = 'c';

Wchar_t: A byte character. Because char occupies one byte in computer storage, it can contain a maximum of 256 characters,
English characters are enough for storage, but there are tens of thousands of Chinese characters, and char can no longer be used.
Therefore, wchar_t occupies two or even four bytes, which is enough to represent other languages.

wchar_t wide_char = L'c'

 

Float: single precision Floating Point double: double Precision Floating Point long double: extended precision
Both types are decimal in concept. double occupies more memory space than float, which indicates more accurate. You can use float as a decimal point.

float _length = 3.5f;double _length = 3.5555long double l_legnth = 3.5e-3L

 

Void: Empty type. It is generally used to indicate objects of no return value or uncertain type.

return void;void* p = 0;

 

Windows XP 32-bit platform value range:

Type

Size

Value Range

Void

0 byte

No value range

Boolean bool

1 byte

True false

Signed short integer short [int]/signed short [int]

2 byte

-32768 ~ 32767

Unsigned short [int]

2 byte

0 ~ 65535

Signed integer int/signed [int]

4 byte

-2147483648 ~ 2147483647

Unsigned [int]

4 byte

0 ~ 4294967295

Signed long integer long [int]/signed long [int]

4 byte

-2147483648 ~ 2147483647

Unsigned long [int]

4 byte

0 ~ 4294967295

Long

8 byte

0 ~ 18446744073709552000

Signed character char/signed char

1 byte

-128 ~ 127

Unsigned escape char

1 byte

0 ~ 255

Wide struct wchar_t (unsigned short .)

2 byte

0 ~ 65535

Float with single precision

4 byte

-3.4E-38 ~ 3.4E + 38

Double with double Precision Floating Point

8 byte

1.7E-308 ~ 1.7E + 308

Long double

8 byte

 

 

Because of the differences between platforms and compilers, the range and memory size of each type are not determined. For details, use the following code (

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.