C + + Start learning 2

Source: Internet
Author: User

Study on the departure of the C + + expedition

1. References

Base type reference: int a = 3; int &b = A;

struct type reference: typedef struct {int x; int y;} Coor;

Coor C1; Coor &c = C1; c.x = 10; C.y = 20; cout << c1.x << c1.y;

Pointer type reference: int a = 10; int *p = &a; int *&q = p; *q = 20; cout << a << Endl;

Function Reference: Fun (int &a, int &b) {}

int x = ten, int y = 20;

Fun (x, y)

2. Const

Base type: const int a = 10; A is a constant

Pointer: const int *p = NULL; int const *P = NULL; Equivalent

int * Const P = NULL;

const INT * Const P = NULL; int const * Const p = NULL; Equivalent

Reference: int x = 10; const int &y = x; x = 20; correct//y = 20; error

3. Function characteristics

Default value, function overload (function with the same name), inline function

4. Memory Management

Application: new,new *p = new int; New *arr = new INT[10]; block memory request and release. Application to determine whether it is empty (empty is wrong)

Release: Delete,delete p; delete []arr; Release to set a null pointer

C + + Start learning 2

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.