C ++ simplify01-basic syntax

Source: Internet
Author: User

Refer to C ++ primer 4th (Chinese Version)

1. Each C ++ program contains one active multiple functions and must be named main. The system calls the main function to execute the program. The main function executes the statement and returns a value to the operating system.

Int main (void)

{

Return 0; // if the return value is 0, the program is successfully executed. Otherwise, the program exits unexpectedly.

}

2. The iostream library is used for C ++ input and output. Istream and ostream indicate the input stream and output stream respectively.

"Stream" refers to the character sequence to be read or written from an IO Device. The input and output use two objects: CIN and cout.

3. The Endl is a special value and acts as a operator. When writing it to the output stream (cout <Endl), it can output line breaks and refresh the buffer associated with the device. "\ N" can also wrap lines, but cannot empty the buffer.

Three methods for clearing the buffer:

A. Flush (stdout); B. cout <flush; C. cout. Flush;

4. differentiate ++ A and A ++:

Int A = 0; ++ A; // (++ A) = 1 and a = 1 is more efficient

Int A = 0; A ++; // (A ++) = 0 but a = 1

5. Loop Structure:

While (conditional expression)

{

...

}

 

Do

{

...

} While (conditional expression );

 

For (initial value; condition; change value ;)

{

...

}

6. Condition branch structure: If () {} else {} switch {Case :}

7. class type: Class keyword Declaration contains data members and member functions (common functions, constructors, and destructor)

8. Basic Types of C ++ languages: String, integer, and floating point (variable-length string, vector ...)

Note: In C ++, it is completely legal to assign a negative value to an unsigned object. The result is the value after the negative value is calculated for the number of values of this type. Therefore, if-1 is assigned to an 8-bit unsigned char, the result is 255, because 255 is the value after-1 for 256 modulo.

9. Literal Value constants: 24, hello, and other data values that cannot be modified.

Three hexadecimal values of an integer constant: decimal: 50; octal: 050 (starting with 0); hexadecimal: 0x50 (starting with 0x ).

Long: 1l unsigned long: 8lu (UL) unsigned: 128u

Float representation: 4.14159f (f) Extension precision: 12.345l scientific Notation: E (e) Suffix

Escape characters:

Common Escape Character: \ ooo

ASCII character set indicates the literal value constant:

\ 7 ringtone \ 12 linefeed \ 40 space character \ 0 blank character \ 062 (2) \ 115 (m)

10. Two adjacent character strings separated by spaces, tabs, or line breaks can be connected to a new character string. Example: cout <"Hello" world "<Endl; helloworld is output

Note: The benefits of a slash: (no spaces or comments are allowed after the slash)

Cout <"a multi-line \

Stringliteral \

Usinga backslash"

<Endl;

Equivalent to cout <"amulti-line string literal using a backslash" <Endl;

 

Three questions per day: 2012.07.26

(1) enter a year to judge whether the year is a year or a leap and output the result.

(2) enter the number of any group (the number is not fixed) for the maximum and minimum values.

(3) solve the mathematical fan. There are the following formula: ABCD-CDC = ABC, where ABCD is a non-negative integer, calculate the value of ABCD.

The source code will be published in the next 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.