C + + top-level const and underlying const

Source: Internet
Author: User

the top-level const is a constant (immutable) that represents the object itself;

The underlying const is a constant (pointed immutable) that represents the object to which it is pointing;

1#include <iostream>2 3 intMain ()4 {5     intI=0;6     int*Constp1=&i;//-----Cannot change the value of P1, which is a top-level const7     Const intB=i;//-----Cannot change the value of B, which is a top-level const (const is the top-level const before the general variable)8     Const int* p2=&b;//-----Can change the value of the P2, which is an underlying const (the object is a const, so you can point to the top layer)9     Const int*ConstP3=P2;//-On the right is the top-level const, on the left to the bottom of the thing const;Ten     Const int& Some=i;//---Used to declare references, are the underlying const; One}

When the copy operation of the object is performed, the difference between the top-level const or the underlying const is obvious, and the top-level const is not affected;

The underlying const execution copy is a type of 2 object that must be the same, or convertible, and the general amount can be converted to constants;

C + + top-level const and underlying const

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.