C ++ Learning (1), Learning

Source: Internet
Author: User

C ++ Learning (1), Learning

C ++ Learning (1)

1. const c vs c ++:

In c, const is a read-only variable (ReadOnly Varible). In c ++, const only represents a Constant (Constant ).

Example:

Const int n = 10;

Int arry [10] // OK in c ++ error in c.

2. Two attributes of the pointer:

(1). pointer itself;

(2) Data pointed to by the pointer;

3. Constant pointers and pointer constants:

(1 ).Constant pointer(Point to constant or constant point ):

Concept: pointer to a constant;

Definition: const int * p;

Example:

Const int * p1;

Const int x = 1;

P1 = & x; // correct

* P1 = 10; // Error

Here, a constant refers to a constant for the solution reference;

(2 ).Pointer constant(Point constant)

Concept: an immutable Pointer Points to a variable value;

Definition: int * const p;

Example:

Const int x = 1

Int * const p1 = & x; // super important step. Be sure to write to whom p1 points.

* P1 = x // or y. You can leave it empty. If you leave it empty, it indicates the value of the variable pointed to by p1;

P1 = & y // incorrect, because the pointer in the pointer constant cannot be changed.

# The array name is a pointer constant !!

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.