Home

A program to explain increment and decrement operators

C Programming Language 009

The following code shows how to write a program to explain increment and decrement operators

Program

#include <stdio.h>

void main()
{
    int a = 3, b;
    printf("a = %d\n", a);

    b = a--;
    printf("After b=a-- \t b=%d \t a=%d \n", b, a);
    b = --a;
    printf("After b=--a \t b=%d \t a=%d \n", b, a);
    b = a++;
    printf("After b=a++ \t b=%d \t a=%d \n", b, a);
    b = ++a;
    printf("After b=++a \t b=%d \t a=%d \n", b, a);
}

Result

a = 3
After b=a--      b=3     a=2
After b=--a      b=1     a=1
After b=a++      b=1     a=2
After b=++a      b=3     a=3


Last Updated on

Next Post: Rules vs Guidelines →

Comments