简体   繁体   中英

In C++, the * is used for what three things?

I know the * operator is overloaded for multiplication and pointing. Is the 3rd use uniary? If so, could someone elaborate?

When used as the pointer dereference operator it is a unary operator.

This is because in that context, it only takes one argument, namely the pointer.

You do see * in 5 contexts (other than quoted strings):

  1. as a multiplication operator
  2. as pointer deference
  3. as multiplication assignment *=
  4. to form part of a type; eg int*
  5. as part of /* and */ comment blocks

In (1) and (2) and (3), it is acting as an operator. C++ allows you to overload operators.

From what I know:

  1. First use: to declare a pointer:

     int * ap; 

    ap is an integer pointer.

  2. To dereference a pointer. *ap gives the value stores at the address pointer to by the pointer ap .
  3. Multiplication, eg int a = 5*2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM