Increases a counter from 1 to 5, printing updates and then counts it back down to 1. - C Operator

C examples for Operator:Compound Operator

Description

Increases a counter from 1 to 5, printing updates and then counts it back down to 1.

Demo Code

#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;
}

Result


Related Tutorials