C examples for Operator:Compound Operator
Increases a counter from 1 to 5, printing updates and then counts it back down to 1.
#include <stdio.h> int main(){//from ww w.j av a 2 s. co m int i = 0; i = i + 1; // increases counter to 1 printf("Counter is at %d.\n", i); i = i + 1; // increases counter to 2 printf("Counter is at %d.\n", i); i = i + 1; // increases counter to 3 printf("Counter is at %d.\n", i); i = i + 1; // increases counter to 4 printf("Counter is at %d.\n", i); i = i + 1; // increases counter to 5 printf("Counter is at %d.\n", i); i = i - 1; // decreases counter to 4 printf("Counter is at %d.\n", i); i = i - 1; // decreases counter to 3 printf("Counter is at %d.\n", i); i = i - 1; // decreases counter to 2 printf("Counter is at %d.\n", i); i = i - 1; // decreases counter to 1 printf("Counter is at %d.\n", i); return 0; }