Home > Back-end >  Chapter 2 c note
Chapter 2 c note

Time:11-09

C + + second chapter

A. Able to handle basic data types of c + +

1. The integral type

2. The real type

3. The character type

Boolean type
4.
2. C + + supports the basic operation of

1. The arithmetic

2. Logic operations

(program to be able to input and output data)

(c + + data input and output can be called the predefined function module realization)

3. Procedures the order of the execution of the process is not always so to

1. Choose to perform process (selection switch statement)

2. Repeat with the same algorithm processing mass data in turn (loop)

4. Basic data type can represent the types of data co., LTD.

5. The characteristics of c + +

1. Compatible with C support process oriented programming

2. Support the object-oriented method

3. Supports generic programming method (in most cases the object-oriented program encapsulation reusability security are better)

//(comment lines)

#include
using namespace std; Namespaces can avoid naming conflicts STD (namespace)

Int main () the main () function program of the main module int regulation calculation result of the function return value should be an integer value

{

Cout & lt; <"Hello!"
Cout & lt; <"Welcome to c + +!"
return 0; return 0; Returns the results of the function

} {} surrounded by the middle of the function body is the methods and steps to solve the problem

Results: Hello!

Welcome to c + +!

Cout defined output stream object (like the cout is an object name for display to send a predefined data objects)


The character set of c + + (only by limited character)

1. The case of the English letters A to Z A to Z

2. The numeric characters 0 ~ 9

3. The special characters! # % ^ & amp;//:? (a) [] {} |

7. The word-formation of c + +

Keyword
1.
C + + the predefined words


2. The identifier
Programmers statement of words, it is named after some entities in the program text

3. The word

In the program directly using the symbol data

4. The separator

{0}, :; Used to separate each lexical markers or program text,

5. The operator (operator)

Used to implement the various operations of symbol

6. Whitespace

Spaces and tabs (TAB characters), vertical tabs, line feeds, carriage returns, and the floorboard of the annotation

(where the could be a space can appear more Spaces)

Only the identifier is programmer own name

Eight. The constitution of the identifier rules:

(beginning with an underscore or a letter)

1 'with a capital letter lowercase letters or underscores

()

2. Can be with a capital letter lowercase

An underscore () or number of 0 ~ 9

3. The uppercase and lowercase letters represent different

Identifiers

4. Can't be a c + + keywords or operator

9. Able to handle basic data types of c + +

1. The integral type

2. The real type

3. The character type

Boolean type
4.
Ten. In the program data

1. Constant

Data is written directly in the source program

Its value cannot be changed during the entire program is run

2. The variable

Permitted to change the data in the process of the program is run (often also need to be changed)

11. Integer type

1. The basic integer types: int (in c + + standard and didn't have a few bytes become basic plastic)

2. Press the symbol points (symbol signed unsigned unsigned)

3. According to the scope of data points

Short integer (short)

Long integer (long)

Long integer (long long)

ISO C + + standard does not specify the number of bytes of each data type and scope, it's just a regulation the number of bytes in size between them order meet:

(signed/unsigned) signed char

\ & lt; (unsigned) short int

\ & lt; (unsigned int)

\ & lt; (unsigned) long int

\ & lt; Long long int

12. The character type (char)

1. Hold a single character encoding

2. Stored in essence is an integer

13. The floating-point type

1. The single precision

2. Double

3. The extended precision

13. The type string

1. A string constant

2. No string variable in the basic types of

3. The character array to store the string (C style of string)

4. The string class in the standard c + + class library (c + + style of string)

Boolean type
fourteen.
1. Only two values: true and false (true) (false)

2. Commonly used to represent the relationship between the comparison, equal comparison or the result of the logical operation



15. Constant

1. The whole process of the program is run in its value is always do not change the amount of

2. Direct use of symbolic value (text),

3. For example: 12,3.5, are A constant

16. The integer constants

1. The decimal

2. The octal

3. The hexadecimal

Take the form of text integer

1. The decimal

A number of 0 ~ 9 Numbers, but digital part cannot begin with 0, in front of a positive number plus can be omitted,

2. The octal

If a leading 0 + thousand of 0 ~ 7 digital

3. The hexadecimal

Leading 0 x + if thousands of 0 ~ 9 Numbers and the letters of A ~ F (case may be) (negative -)

4. The suffix

Suffix L (or I) type is at least a long

The suffix LL (or II) type is long long

The suffix U (or U) said unsigned types

17. Floating-point constant

1. In text in the form of real number

2. One - a form:

For example, 12.5, 12.5, etc.

3. The index form

For example, 0.345 e+2, 34.4 e-3

The integer part and decimal part can be omitted one

4. Floating-point constant defaults to double, if the suffix F (F) can make it a float type

For example: 12.3 f

Some characters are special characters can't display on the screen with translation characters



18. C style of string constants

1. A sequence of characters enclosed in double quotation marks

2. In memory by the string of characters in order to store the order, each character of a byte

3. In the end add '\ 0' as the ending tag

For example,



19. By adding a prefix can change the type of character constants or string constants



Twenty. Variable

1. In the process of the program runs the variable value amount of

21. While defining variables can also be initialized to it

In c + + language offers a variety of initialization method:

For example:

Int a=0

Int a (0)

Int a={0}

Int a {0}

22. Initialization list

1. The use of braces initialization method known as the initialization list,

2. The list of initialization time does not allow the loss of information,

For example:

With a double value to initialize the int variable, can cause data loss

23. Symbolic constant

The form of the constants defined statement for:

1. The const data type specifier constant name=constant values.

2. Or data type specifier const constant name=constant values

For example: define a symbolic constant on behalf of the PI. Const floatPI=3.1415926

3. The symbolic constants in the definition must be initialized in the middle of the program cannot change its value

Mainly knowledge single

1. Constant

Directly in the source program data indicating its value cannot be changed during the whole program run, such data as constants,

2. The variable

In the process of running from the computer peripheral equipment (such as a keyboard, hard drive) is read, the value of the data in the process of the program is running allows the change, such data as variables,

(3) from the keyboard input data

Iostream class object cin & gt;> Operation, can from the standard input device (usually a keyboard) read in data,

4. Data storage

For these data to store data, need to allocate memory space, the definition of a variable is in when allocating memory for naming a variable space,

The main points: symbolic constant

#include

using namespace std;

Int main ()

{const double PI (3.14159); That PI is a constant

Int the radius;

Cout<"Both Please enter the radius. \n";

Cin> The radius.

Cout<& lt;" The radius is: "& lt;
  • Related