简体   繁体   English

C ++中的指针运算符列表

[英]List of operators on pointers in C++

对于C ++中给定的原始指针类型T* ptr ,在其上定义的所有运算符的列表是什么?

List of operators that I can think of: 我能想到的运算符列表:

  1. The assignment operator - ptr = some other pointer 赋值运算符ptr = some other pointer
  2. The dereference operator - *ptr . 解引用运算符- *ptr
  3. The array operator - ptr[N] . 数组运算符ptr[N]
  4. The member access operator ptr-> if T is a struct/class. 成员访问运算符ptr->如果T是结构/类)。
  5. The pre and post increment operators - ++ptr and ptr++ . 前后递增运算符- ++ptrptr++
  6. The pre and post decrement operators - --ptr and ptr-- . 递减前后的运算符--- --ptrptr--
  7. The increment and assign operator - ptr += N . 增量和赋值运算符ptr += N
  8. The decrement and assign operator - ptr -= N . 减法和赋值运算符ptr -= N
  9. The unary + operator: +ptr . 一元+运算符: +ptr Note that this is not valid in C99. 请注意,这在C99中无效。 It is valid only in C++. 仅在C ++中有效。
  10. The binary + operator - ptr + N . 二进制+运算符ptr + N
  11. The binary - operator - ptr - N and ptr1 - ptr2 . 二进制-运营商- ptr - Nptr1 - ptr2
  12. Is equal to: ptr == some other pointer . 等于: ptr == some other pointer
  13. Is not equal to: ptr != some other pointer . 不等于: ptr != some other pointer
  14. The unary not operator: !ptr . 一元not运算符: !ptr
  15. Less than operator : ptr < some other pointer . 小于运算符: ptr < some other pointer
  16. Less than or equal to operator: ptr <= some other pointer . 小于或等于运算符: ptr <= some other pointer
  17. Greater than operator : ptr > some other pointer . 大于运算符: ptr > some other pointer
  18. Greater than or equal to operator: ptr >= some other pointer . 大于或等于运算符: ptr >= some other pointer
  19. The address of operator: &ptr . 操作员的地址: &ptr

Assuming 假设

T* t;

dereference 提领

(*t).foo

or 要么

t->foo

pointer arithmetic 指针算术

t = t + 10; t += 10; // will add 10*sizeof(T)
t = t - 10; t -= 10; // will subtract 10*sizeof(T)

--t;
++t;
t--;
t++;

access like an array: (usually frowned upon) 像数组一样访问:(通常不赞成)

t[10]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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