Relive C + + (i)

Source: Internet
Author: User
Tags arithmetic constant definition

Meaning of 0 and 1:

In the computer 0 and the switch representing the logic circuit, where 1 is closed and 0 is disconnected.

0 and 1 can be used to represent all the data in the computer, such as colors, pictures, videos, executable programs, such as can be made up of 32 0 000000000000000000~ representing white;

Binary:

2 The one in the binary is a bit, and 8 bits make up one byte;

Binary vs. decimal conversions:

Decimal, binary: a2a1a0=a0*2^0+a1*2^1+a2*2^2;

Decimal---binary: short division, dividing 10 binary number by 2 and the resulting quotient divided by 2, For example: 10->2 10/2=5 (remainder) 0,5/2=1 (remainder) 1,1/2=0 (remainder) 1, the corresponding binary is: 110

Variable:

When the program runs, it allocates memory space to the variable, and accessing the variable name actually accesses the memory space.

Types and ranges of variables:

Ref: 8790241

Machine Word length: Refers to the number of bits of binary data that a computer can handle in an integer operation (integer operation is a fixed-point integer operation). The machine word length is the length of the fixed-point arithmetic, usually the width of the internal data path of the CPU. It is now generally 32 bits, which is 4 bytes, and also 64-bit and 16-bit.

The arithmetic type of storage space is determined by the machine. In general, the short type is half machine word length, int is a machine word length, long is 1 or 2 machine word length, float is a machine length, double is two characters, long double is 3 or 4 words. The C + + standard specifies the minimum storage space for each arithmetic type, but it does not prevent the compiler from having larger storage space. If you want to ensure portability, try to use __int16 __int32 __int64 bar, or your own typedef int INT32 a bit.

Data type name Number of bytes Alias Range of values
Int * signed,signed int Determined by the operating system, which is related to the "word length" of the operating system
unsigned int * Unsigned Determined by the operating system, which is related to the "word length" of the operating system
__int8 1 char,signed Char –128 to 127
__int16 2 Short,short int,signed Short int –32,768 to 32,767
__int32 4 signed,signed int –2,147,483,648 to 2,147,483,647
__int64 8 No –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
bool 1 No False or True
Char 1 Signed Char –128 to 127
unsigned char 1 No 0 to 255
Short 2 Short int,signed Short int –32,768 to 32,767
unsigned short 2 unsigned short int 0 to 65,535
Long 4 Long int,signed Long int –2,147,483,648 to 2,147,483,647
Long Long 8 None (but equivalent to __int64) –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long 4 unsigned long int 0 to 4,294,967,295
Enum * No Determined by the operating system, which is related to the "word length" of the operating system
Float 4 No 3.4E +/-(7 digits)
Double 8 No 1.7E +/-308 (digits)
Long double 8 No 1.7E +/-308 (digits)
wchar_t 2 __wchar_t 0 to 65,535

(P: The size of the pointer is a fixed value of 4 bytes)

The results in the 32-bit machine environment are as follows:

Type

Size

Range of values

No-value void

0 byte

No domain

boolean bool

1 byte

True False

signed short [int]/signed shorter [int]

2 byte

-32768~32767

Unsigned short-integer unsigned shorter [int]

2 byte

0~65535

Signed integral type int/signed [int]

4 byte

-2147483648~2147483647

unsigned integral type unsigned [int]

4 byte

0~4294967295

Signed long [int]/signed long [int]

4 byte

-2147483648~2147483647

unsigned long integer unsigned [int]

4 byte

0~4294967295

Long Long

8 byte

0~18446744073709552000

Signed character type char/signed Char

1 byte

-128~127

unsigned character type unsigned char

1 byte

0~255

Wide character type wchar_t (unsigned short.)

2 byte

0~65535

Single-precision float float

4 byte

-3.4e-38~3.4e+38

Double-precision floating-point double

8 byte

1.7e-308~1.7e+308

Long double

8 byte

The length of the specific type can be viewed with sizeof.

Signed integer calculation: treat the highest bit as a sign bit

The sign bit is 0: non-negative, and the remainder is even if the absolute value of the integer

The sign bit is 1: Negative number, the remaining digits equals the first absolute value of the integer plus 1; Take the absolute value-----plus 1

-1, 1000 0001, 1111 1110, 1111 1111
-2, 1000 0010, 1111 1101, 1111 1110

-3, 1000 0011, 1111 1100, 1111 1101

-4, 1000 0100, 1111 1011, 1111 1100

-5, 1000 0101, 1111 1010, 1111 1011

Constant definition: #define

Input and output:

\ "" means double quotation marks,

Relive C + + (i)

Related Article

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.