C ++ learning notes (1) pointer: learning notes pointer

Source: Internet
Author: User

C ++ learning notes (1) pointer: learning notes pointer

Pointer Reference

1 int I = 1; 2 int * p; 3 int * & r = p; // r is a reference to pointer p 4 r = & I; // r is a reference to p, so the value assigned to r is that p points to i5 * r = 2; // update the I value

 

  • You can update the value pointed to by the pointer in * p mode.
  • You can declare a reference to the pointer and perform related operations on behalf of the pointer.

Pointer to a constant

1 const double pi = 3.14; 2 const double * ptr = & pi; // correct 3 double * err = & pi; // error, err is a normal pointer
  • The pointer type must be the same as the indicated type. But there are exceptions
    • Allows a pointer pointing to a constant
    • The object indicated by a pointer to a constant may not be a 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.