Three types *

Source: Internet
Author: User

In C ++, * has three usage methods:
1) multiplication number, for example, a * B;
2) pointer type, for example, int * P;
3) value of the pointer type variable, for example, int B = * P.

(1) * is an independent binary operator. It does not have a special meaning for the two variables before and after;

For 2), we should regard "int *" as a new type, int pointer type. P is the name of the variable, and "int *" is the type of the P variable. That is to say, * can be used with any class or type to form a new type of "classname *" or "typename. This new type indicates a memory address segment by the name of the first half and * of the second half:

* It indicates that the value of P is the starting position of a memory address segment (for 32-bit operating systems, P is an 8-bit hexadecimal number );
Name indicates the length of the memory address indicated by P, which is the size of the class or type.

* P indicates that this variable is a pointer type and stores a memory address (the starting address of a certain data in the memory), but most of the time this does not make any sense. We need to know the length of the data in the memory, which is determined by the class or type in front, the p type will change from the "pointer type" to a meaningful "pointer type ".
For * in 2), it does not have any meaning when it exists independently, nor does it make sense to append it to variable name P. It is complete only after being attached to a class or type.

3), * is a unary operator. Its operands must be of a pointer type, and it returns a value of a certain type.

For encoding habits of 2) and 3), I like to use the following space format:

Int *P = &;
Int B =* P;

And do not like to use

Int * P = &;
Int B = * P;

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.