随笔 - C 语言中的 "操作符" "-->"

https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c 看到个好玩的东西

1.cview raw
1
2
3
4
5
6
#include <stdio.h>
int main() {
int x = 10;
while (x-- > 0) // x goes to 0
printf("%d ", x);
}

这段代码的输出是

1
9 8 7 6 5 4 3 2 1 0

这里的 --> 看起来就像操作符一样

实际上 while (x --> 0) 的意义是 while ((x--) > 0)

类似的,我们还可以写出 while (x ----> 0) -> 8 6 4 2 0

我们也可以一定程度上假装用 CPascal 程序

2.cview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define upto ++ <
#define downto -- >
#define for while(
#define do )
#define begin {
#define end }

#include <stdio.h>
int main() {
int x = 10;
for
x downto 0 do begin printf("%d ", x);
end
}