c++| | Variable

Source: Internet
Author: User

C + + defines several basic types: character, integer, floating-point

1. Basic built-in type

C + + defines a set of arithmetic types (arithmetic type) that represent integers, floating-point numbers, and single characters that define void special types that do not have corresponding values and are used as types with no return value

The arithmetic type of storage space depends on the machine, size is used to describe the type of binary (bit), C + + specifies the minimum storage space for each arithmetic type.

C + + arithmetic type
Type Mean Min Storage space
bool bool --
Char Char 8bit
wchar_t Wide Char 16bit
Short Short int 16bit
Int Int 16bit
Long Long int 32bit
Float Single float 6 numbers
Double Double float Ten numbers
Long double Extra float Ten numbers

1.2 Integral type

Integer and Boolean arithmetic types are collectively known as integers (integral type)

The character type contains: Char and Wchar_t,char make sure that has enough spacce, can storage machine basic any value, so that char is sing Le byte.

wchar_t type is extra Unicode, but these can is not show single char.

  

!addition:

Stores a method with a structure that uses blocks (chunk) to handle storage, a power of bits 2 of a block, usually a 8-bit fast bit of one byte (byte), or 4 bit is a word!;

  

Short, int., long show integral type,the different of the storage space, short are the half word, int is one word,and long h As one or 2 word.

BOOL Show the true or FALSE, 0 =false 1=true;

1.3 Signed & unsigned

Export bool,intergral can signed or unsigned, that can show The-1,and unsigned need >=0.

  

Char has 3 different type, it is char,signed char and unsigned char,

1.4 Show for Integral

All bits in the unsigned represent numeric values, the definition type is represented by 8 bits, and the unsigned value is 0-255

!addition

The negative value to the unsigned object is legal, the result of the number of type values in accordance with if the 1 is assigned to unsigned char, then the result 255 is-1 to 256 modulo value

1.5float

Float mostly show by 2word (64bit), long double with 3or 4 (96or-bit)

!addition

Suggest to include arthimetic type

Mostly use int can reduce mistake happen, in fact, long is the same as int.

1.6LITERAL CONSTANT

Built-in type has literal values and no literal literals of any kind

Eine:the rules literal

We can use any of the there of one:10, 8 or example:

//decimal

024//octal

0x14//hexadecimal

When defining long integers, you should use the uppercase letter L!!!!!!!

Drei:the rules Float

You can usually use decimal to represent a floating-point literal constant, with E, followed by the default floating-point number plus F or f for single precision.

1.7 non-printable characters to escape sequences

When some characters appear non-printable, you can use a special character representation, and C + + defines the characters:

Line break \ n Horizontal tab \ t

Portrait tab \v backspace \b

Carriage return \ r input character \f

Double quotation marks \ "

1.8 String Literals

The literal value is represented by multiple or 0 characters that are expanded with double quotation marks. \or "" Can be used when a connection is required

2. Variables

C + + provides a unique type that determines the memory size and layout of a variable, the ability to store a value range and the set of operations that can be applied to the variable, called a variable or object

Lvalue and right-0

LVALUE (Ell-value): Left or right of an assignment statement

Are-value: The right side can only appear to the right of the assignment and cannot appear to the left of the assignment statement.

EXAMPLE:]

int units_sold = 0;

Double sales_price = 0,total_revenue=0;

2.1 Variable Name

The identifier of the variable (IDENTIFIER), consisting of letters, numbers, and underscores. Must consist of letters or underscores,

Habit:

1. Variable name is lowercase letter

2. Use the name of the Help memory

3. Include multiple words with underline

2.2 Defining objects

The definition begins with the type specifier (specifier), ending with a semicolon. Type description specifies the type str::string associated with the object, which is the type name.

int and double are built-in types, and std::string is the standard library definition type.

2.3 Initialization

C + + provides 2 forms of variable form

(1): Copy initialization (=)

(2) Direct initialization of EMP (1024)

2.4 Scopes

The context that distinguishes the different meanings of a name is scope (scope), main is the global scope, and sum is the local scope for the statement scope

2.5const Qualifier

object is a local variable of the file,

2.6 References

A composite type, defined in &, and then referenced in a case where each reference type is associated to a different type and must be initialized with the same type of object as the reference.

2.7typedef

Used to define a synonym for a type, with the keyword typedef primarily used for the following purposes     

1. Hide specific types of implementations

2. Simplifying Complex definitions

3. Allow one type for multiple purposes

2.8 Enumeration

Defines an enum as an optional enumeration alias, in which case the first enumeration member variable is 1 followed by each member +1, and in general the enumeration defines the variable as a constant, and the value must be a constant expression (constant expression)

For example:

Enum Forms (Shape =1,s,s2,s3 ...);

2.9 class Type

Define the class to customize the data type, and design the interface implementation in the definition. When defining a variable, use the access modifier to define a variable, and in the access designator as a member of the code that controls the class, the label public,private can appear multiple times in the code block

Structs keyword, the role of members is equal to public.

3.0 Preprocessor

# include is used as C + + for the preprocessor, indicating only one parameter header file name, and the internal Header protector (header Guard) to avoid multiple processing of content

  

c++| | Variable

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.