C + + Primer Plus (ii)--Start learning C + +

Source: Internet
Author: User
Tags function prototype

2.1 entering C + +

1. The C + + function header describes the interface between the function and the function that invokes it,and the function header of the main function describes the interface between main and the operating system.

2. C + + comments begin with // ,C comments are included between function /**/

Header file Type

Conventions

Example

Description

C + + Old Style

end with . h

Iostream.h

C + + programs can use

C Old Style

end with . h

Math.h

C + + programs can use

C + + New Style

Does not have a name extension

Iostream

C + + programs can be used, using namespace std

after the converted C

plus prefix c

Cmath

C + + programs can be used, you can use features that are not C , such as namespace Std

3. namespaces are used when writing large programs to differentiate between versions of different vendors.

4. The Endl control and \ n newline characters can indicate line breaks, except that the Endl control ensures that the program refreshes the output before it continues to run, and that the escape character \ n does not provide such a guarantee, which means that in some systems, Sometimes you may have to enter it before the prompt appears.

5. C + + source style:

(1) Each statement occupies one line

(2) each function has a start brace and a closing curly brace, with two curly braces

(3) the statements in the function are indented relative to the curly braces

(4) There is no white space around the parentheses associated with the function

2.2 C + + statements

for declaring variables, the practice of C + + is to declare it as much as possible before using the variable for the first time.

2.3 class

1. A class is a user-defined data type that describes how information is represented and what operations can be performed on the data, and objects are entities created from these descriptions

2. C + + provides two ways to send information: one is by using a class method, and the other is to redefine the operator

2.4 function

1. The parameter is the information sent to the function, and the return value is the value sent back from the function

2. function prototypes to functions are like variables declared to variables -- indicating the types involved, andC + + programs should provide prototypes for each function used in the program.

3. usually put the prototype before the main () definition, put the implementation after main ()

4. The function prototype describes the function interface, that is, how the function interacts with the rest of the program; The parameter list indicates what information will be passed to the parameter; the type of the function

5. There are many ways to make a program use namespaces (where xxx represents a space name andyyy represents an element in space):

(1) using namespace xxx;// all elements in a namespace

(2) using xxx::yyy;// a specific element in a pre-specified namespace can be used

(3) xxx::yyy; when you need to use it, introduce the elements in your namespace




C + + Primer Plus (ii)--Start learning C + +

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.