C语言基础:自增自减符号位置的区别,– a和a–的区别演示
#include <stdio.h> int main () { int value = 1; printf("Using postfix %d\n", value--); printf("Value after decrement %d\n", value); value = 1; printf("Using prefix %d\n", --value); printf("Value after decrement %d\n", value); return 1; }
gcc编译运行结果
Using postfix 1 Value after decrement 0 Using prefix 0 Value after decrement 0
自增代码
#include <stdio.h> int main () { int value = 1; printf("Using postfix %d\n", value++); printf("Value after increment %d\n", value); value = 1; printf("Using prefix %d\n", ++value); printf("Value after increment %d\n", value); return 1; }
gcc编译运行结果
Using postfix 1 Value after increment 2 Using prefix 2 Value after increment 2