C language prefix and postfix increment or decrement operators

1. Prefix increment/decrement (++a / --a)

  • When using prepending increment or decrement, the variable is first incremented or decremented by 1, and then the new value is returned.
int a = 5;

int b = ++a; 

// 先将a加1变为6,然后将6赋给b,所以之后a为6,b也为6。

2. Postincrement/decrement (a++) / (a- -)

  • The operation of the post-fixed version is to return the current value of the variable first, and then increase or decrease it by 1.
int a = 5;

int b = a++; 

// 先将a的当前值5赋给b,然后将a加1变为6,所以之后a为6,b仍为5。


      

Acho que você gosta

Origin blog.csdn.net/W_Fe5/article/details/135425886
Recomendado
Clasificación