• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Test operators */
2 
testInc()3 void testInc() { int a, b; a = 3; b = a++; printf("3++ = %d %d\n", b, a); }
testDec()4 void testDec() { int a, b; a = 3; b = a--; printf("3-- = %d %d\n", b, a); }
testTimes()5 void testTimes(){ printf("%d * %d = %d\n", 10, 4, 10 * 4); }
testDiv()6 void testDiv(){ printf("%d / %d = %d\n", 11, 4, 11 / 4); }
testMod()7 void testMod(){ printf("%d %% %d = %d\n", 11, 4, 11 % 4); }
testPlus()8 void testPlus(){ printf("%d + %d = %d\n", 10, 4, 10 + 4); }
testMinus()9 void testMinus(){ printf("%d - %d = %d\n", 10, 4, 10 - 4); }
testShiftLeft()10 void testShiftLeft(){ printf("%d << %d = %d\n", 10, 4, 10 << 4); }
testShiftRight()11 void testShiftRight(){ printf("%d >> %d = %d\n", 100, 4, 100 >> 4); }
testLess()12 void testLess(){ printf("%d < %d = %d\n", 10, 4, 10 < 4); }
testLesEqual()13 void testLesEqual(){ printf("%d <= %d = %d\n", 10, 4, 10 <= 4); }
testGreater()14 void testGreater(){ printf("%d > %d = %d\n", 10, 4, 10 > 4); }
testGreaterEqual()15 void testGreaterEqual(){ printf("%d >= %d = %d\n", 10, 4, 10 >= 4); }
testEqualTo()16 void testEqualTo(){ printf("%d == %d = %d\n", 10, 4, 10 == 4); }
testNotEqualTo()17 void testNotEqualTo(){ printf("%d != %d = %d\n", 10, 4, 10 != 4); }
testBitAnd()18 void testBitAnd(){ printf("%d & %d = %d\n", 10, 7, 10 & 7); }
testBitXor()19 void testBitXor(){ printf("%d ^ %d = %d\n", 10, 7, 10 ^ 7); }
testBitOr()20 void testBitOr(){ printf("%d | %d = %d\n", 10, 4, 10 | 4); }
testAssignment()21 void testAssignment(){ int a, b; a = 3; b = a; printf("b == %d\n", b); }
testLogicalAnd()22 void testLogicalAnd(){ printf("%d && %d = %d\n", 10, 4, 10 && 4); }
testLogicalOr()23 void testLogicalOr(){ printf("%d || %d = %d\n", 10, 4, 10 || 4); }
testAddressOf()24 void testAddressOf(){ int a; printf("&a is %d\n", &a); }
testPointerIndirection()25 void testPointerIndirection(){ int a, b; a = &b; b = 17; printf("*%d  = %d =?= %d\n", a, * (int*) a, b); }
testNegation()26 void testNegation(){ printf("-%d = %d\n", 10, -10); }
testUnaryPlus()27 void testUnaryPlus(){ printf("+%d = %d\n", 10, +10); }
testUnaryNot()28 void testUnaryNot(){ printf("!%d = %d\n", 10, !10); }
testBitNot()29 void testBitNot(){ printf("~%d = %d\n", 10, ~10); }
30 
main(int a,char ** b)31 int main(int a, char** b) {
32     testInc();
33     testDec();
34     testTimes();
35     testDiv();
36     testMod();
37     testPlus();
38     testMinus();
39     testShiftLeft();
40     testShiftRight();
41     testLess();
42     testLesEqual();
43     testGreater();
44     testGreaterEqual();
45     testEqualTo();
46     testNotEqualTo();
47     testBitAnd();
48     testBinXor();
49     testBitOr();
50     testAssignment();
51     testLogicalAnd();
52     testLogicalOr();
53     testAddressOf();
54     testPointerIndirection();
55     testNegation();
56     testUnaryPlus();
57     testUnaryNot();
58     testBitNot();
59     return 0;
60 }
61