Home | History | Annotate | Download | only in data
      1 // Test assignment operations
      2 
      3 void testAssignment() {
      4     int a = 2;
      5     a *= 5;
      6     printf("2 *= 5  %d\n", a);
      7     a = 20;
      8     a /= 5;
      9     printf("20 /= 5  %d\n", a);
     10     a = 17;
     11     a %= 5;
     12     printf("17 %%= 5  %d\n", a);
     13     a = 17;
     14     a += 5;
     15     printf("17 += 5  %d\n", a);
     16     a = 17;
     17     a-=5;
     18     printf("17 -= 5  %d\n", a);
     19     a = 17;
     20     a<<=1;
     21     printf("17<<= 1  %d\n", a);
     22     a = 17;
     23     a>>=1;
     24     printf("17>>= 1  %d\n", a);
     25     a = 17;
     26     a&=1;
     27     printf("17&= 1  %d\n", a);
     28     a = 17;
     29     a^=1;
     30     printf("17^= 1  %d\n", a);
     31     a = 16;
     32     a^=1;
     33     printf("16|= 1  %d\n", a);
     34 }
     35 
     36 int a;
     37 
     38 int* f() {
     39     printf("f()\n");
     40     return &a;
     41 }
     42 
     43 void testEval() {
     44     a = 0;
     45     printf("*f() = *f() + 10;\n");
     46     *f() = *f() + 10;
     47     printf("a = %d\n", a);
     48 }
     49 
     50 void testOpEval() {
     51     a = 0;
     52     printf("*f() += 10;\n");
     53     *f() += 10;
     54     printf("a = %d\n", a);
     55 }
     56 
     57 int main() {
     58     testAssignment();
     59     testEval();
     60     testOpEval();
     61     return 0;
     62 }
     63