Two special Operators related to pointers and Their Equivalent Expressions

Source: Internet
Author: User

Two special Operators related to pointers:

1. "&" the address operator can be used to retrieve the addresses of common variables;

2. "*" has two meanings:

1. pointer flag: whether the pointer flag is used depends on whether there is a type in the front. Here there is an int

2. pointer OPERATOR:

The value is on the right of the equal sign. * The values of common variables pointed to by pointer variables can be retrieved.

Assign a value to the left of the equal sign. * You can change the value of the common variable pointed to by the pointer variable to another variable.

3. It is a multiplication operator. Only when both the left and right are variables. .

For example

Int a, B = 20, c = 30, d = 40, * p; (correct, here * is the pointer sign, which only serves to the left and right of the definition, no value or value assignment function. Whether it is a pointer flag mainly depends on whether there is a type in the front, where there is an int at the top)

P = & d; (correct, p points to the address of d)

A = * p; (correct, here * is the value. Finally, the value of a is changed to 40 of d)

* P = c; (correct, * here is the value. Finally, the value of d is changed to the value 30 of C)

* P = & B; (RUN error, content value on the left, address on the right, not equivalent)

----------------------------

Equivalent expression

If the pointer Variable p points to variable a, the address of variable a is assigned to the pointer Variable p.

For example, int a = 20, * p = &;

The result is as follows:

A, * p <=>

B, p <=> &

C. & * p <=> & a <=> p

D, * & a <=> * p <=>

E, (* p) ++ a ++

(* P) -- --

++ (* P) ++ a ++ * p

-- (* P) -- a -- * p

 

Related Article

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.