C + + learning (1)

Source: Internet
Author: User

C + + learning (1)

1.const C VS C + +:

In the C language , const is a read-only variable (ReadOnly varible), and in C + + Const represents only constants (Constant ).

Cases:

const int n=10;

int Arry[10]//ok in C + + error in C.

2. Two properties of the pointer:

(1). The pointer itself;

(2). The data that the pointer points to;

3. constant pointer and pointer constants:

(1). constant Pointer (point toconstant or constantpoint):

Concept: A pointer to a constant;

Definition:const int* p;

Cases:

const int * p1;

const int x=1;

p1=&x;// Correct

*p1=10;// Error

Here constant refers to the solution reference is a constant;

(2). pointer constant (pointconstant)

Concept: The immutable pointer points to a variable value;

Definition:int* const p;

Cases:

const INT X=1

int* Const p1=&x;// A super important step, be sure to write on P1 who to point to

*p1 = x//or y, also can not write, do not write the words represent the value of the variable that P1 points to;

p1=&y// is wrong because the pointer is not variable in the pointer constant

# The array name is a pointer constant!!

C + + learning (1)

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.