据我了解, a++ 是后缀增量,它将 a 加 1 并返回原始值。++a 是前缀递增,它给广告加 1 返回新值。
我想尝试一下,但在这两种情况下,它都会返回新值。我有什么误解?
#include <stdio.h>
int main() {
int a = 0;
int b = 0;
printf("%d\n", a); // prints 0
printf("%d\n", b); // prints 0
a++; // a++ is known as postfix. Add 1 to a, returns the old value.
++b; // ++b is known as prefix. Add 1 to b, returns the new value.
printf("%d\n", a); // prints 1, should print 0?
printf("%d\n", b); // prints 1, should print 1
return 0;
}