A sentence distinguishes between constant pointers and pointer constants

Source: Internet
Author: User

People who have studied C or C + + know that when they first touch the pointer, they are always confused by constant pointers and pointer constants. Yesterday I thought of a way to make it easy for everyone to distinguish between the two.

First look at the two ways of writing:

Constant pointer:

int const *N, or const int *n;

Pointer constants:

int *const N;

Here we read the const as ' constant ', read the asterisk as a ' pointer ', read it in the order of the const and asterisks in the code (ignoring the other words) is just the right name for both, try it!

I believe that we can correct the code to distinguish what is a constant pointer, what is the pointer constant. If you are not familiar with the characteristics of constant pointers and pointer constants, check the data yourself, these are good distinctions.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

A sentence distinguishes between constant pointers and pointer constants

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.