C + + Notes

Source: Internet
Author: User

Data type

BOOL Boolean type

Char character 8-bit

  wchar_t Wide-character 16-bit

Short 16-bit

int shaping 16 bits

Long length 32 bit

Float single-precision floating-point 6 is a valid number

Double dual-precision floating-point 10-bit valid digits

Long double extended precision floating-point 10-bit valid digits

modifier : The data type can precede one and more modifiers, such as a long long, the previous modifier, and the latter a type

    • Signed
    • Unsigned
    • Short
    • Long

typedef is used to alias an existing data type

The sizeof () function can get the size of the type

struct

Enum

C + + array definition and assignment: int ar[] Char ch[]

C + + string : C + + can use a char array instead of a string, or you can introduce a <string> header file, using the string constructor;

{' abc ', ' Def ', ' jnm '} can be seen as a string array, array elements are char arrays

Constants: Using the const keyword, or the # define definition

------------------------------------------------------------------------

Storage class: Modifiers

    • Auto
    • Register
    • Static
    • extern
    • mutable
    • Thread_local (C++11)

-------------------------------------------------------------------------

The difference between a pointer and a reference

int i=1;      int& r=i; R is a reference to I

int *p=&i;

The pointer definition * does not have to be adjacent to int or p, int* p int *p int * p are compiled correctly

Choose different formats to make your code easier to read according to different situations

----------------------------------------------------------------------------

Object oriented

Class

Classes in C + + can be thought of as a data organization that can be at the same level as a function or struct, unlike a class in Java that is a Java file

The structure of classes in C + +:

Class Demo

{

Public

int A;

int func ()

{

return 0;

}

Private

int b;

}

class member modifier: Public protect Private (default)

Class member functions: can be declared and defined in a class (function body), or only declared in a class, using:: operator is defined outside the class;

Constructors and destructors: destructors are used to delete objects

Copy constructor, inline function, friend function

---------------------------------------------------------------------------------------

Inheritance of classes in C + +, a class can have multiple direct parent classes, multiple inheritance (if multiple direct parent classes have the same name variable or function, how to handle)

Syntax for inheritance: Class derived class: Access Adornment's baseline class {}

Think: The same class, derived classes, external classes have 3, 2, one access rights, public protect private (default);

Which functions are inherited by derived classes, and which do not (base class constructors, destructors and copy constructors, overloaded operators for base classes, friend functions for base classes)

---------------------------------------------------------------------------------------------

C + + polymorphism vs. Java polymorphism

Virtual functions, using the virtual keyword definition, telling the compiler not to statically link, redefining virtual functions in derived classes (equivalent to Java method overrides), calling unused override methods based on the type of the derived class

Pure virtual function, no method body, method body with = 0; instead, this is a pure virtual function, equivalent to the abstract method in Java

Interface (abstract Class): There is at least one pure virtual function, which differs from the interface and abstract classes in Java.

---------------------------------------------------------------------------------------------------

The difference between Java generics and C + + templates, Java generics are syntactic sugars, and templates have many differences

-----------------------------------------------------------------------------------------

Namespaces: You cannot have variables and functions with the same name under the same namespace, and namespaces represent a range

Definition and use of namespaces

Using the namespace keyword definition

Namespace space name {code .... }

Using namespace ...

Using scope operators:: Calling functions in a specific namespace

------------------------------------------------------------------------------------------

C + + STL: A Java-like collection framework that encapsulates the operation of some data structures

--------------------------------------------------------------------------------------

Dynamic memory allocation

The malloc () and free () function families are used in the C language

Using the new and delete operators in C + +

malloc () function prototypes and their use

(void *) malloc (int size)

The malloc function return value is a pointer of type void, and the received parameter is of type int

Calling the malloc function requires that the void type pointer be cast to a specific data type pointer and then assigned to the pointer variable

char *p = (char *)malloc(+);

Free () function frees memory, parameter is memory first address

 Free (p);

After freeing memory with the free () function, the value of the P pointer does not change, and in order to prevent errors caused by the use of the P pointer again, it should be p=null;

----------------------------------------------------------------------

Use of the new operator,new can be used to request memory allocations , or to create class objects

An object created with new needs to be received with a pointer variable that is in heap memory and deletes the object using the Delete object name

Objects not created with new are stored in stack memory

The difference between malloc and new: Because malloc is a function, the compiler cannot control it, but the object is created and the constructor needs to be executed automatically, and the destructor is executed when it is deleted, so C + + uses the new operator to allocate memory

------------------------------------------------------------------------------

Changes in stack and register when function execution

EBP register save Stack Bottom address

ESP register save stack Top address

When another function is called in one function

First, the current function of the bottom of the stack address, that is, the value of the EBP register stack, the ESP address increased by 1,

Storing values in the ESP in EBP

ESP increased by 1

In this way, the address value in the EBP register points to the stored value in memory that is the bottom of the calling function of the current function.

Http://www.cnblogs.com/syw-casualet/p/5223595.html

C + + Notes

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.