How to use postfix Increment and decrement in c language

program to use postfix Increment and decrement in c language


#include<stdio.h>
int main()
{
    int s=10;
    printf("s=%d\t",s);
    printf("s=%d\t",s++);
    printf("s=%d\t",s);
    printf("s=%d\t",s--);
    printf("s=%d\n",s);
    return 0;
}

output


s=10     s=10     s=11     s=11     s=10 

Steps Description

  1. Declare integer variable S=10
  2. Initialize in integer variable S=10
  3. printf inbuild function to display value of variable S in decimal place holder %d S = 10
    for formatting tab separator \t is used
  4. printf inbuild function to display postfix increment values variable S in decimal
    place holder %d S = 10 for formatting tab separator \t is used
  5. printf inbuild function to display value of variable S in decimal place holder %d S = 11
    for formatting tab separator \t is used
  6. printf inbuild function to display post decrement values variable S in decimal place holder %d S = 11 for formatting tab separator \t is used
  7. printf inbuild function to display value of variable S in decimal place holder %d S = 10
    for formatting tab separator \t is used

How to use prefix increment decrement in c language

program to use prefix increment decrement in c language


#include<stdio.h>
int main()
{
    int a=6;
    printf("a=%d\t",a);
    printf("a=%d\t",++a);
    printf("a=%d\t",a);
    printf("a=%d\t",--a);
    printf("a=%d\n",a);
    return 0;
}

output


a=6     a=7     a=7     a=6     a=6

Steps Description

  1. Declare integer variable a=6
  2. Initialize in integer variable a=6
  3. printf inbuild function to display value of variable a in decimal placeholder %d a = 6 for
    formatting tab separator \t is used
  4. printf inbuild function to display prefix increment values variable a in decimal placeholder
    %d a = 7 for formatting tab separator \t is used
  5. printf inbuild function to display value of variable a in decimal placeholder %d a = 7 for
    formatting tab separator \t is used
  6. printf inbuild function to display prefix decrement values variable a in decimal placeholder %d a = 6 for formatting tab separator \t is used
  7. printf inbuild function to display value of variable a in decimal placeholder %d a = 6 for
    formatting tab separator \t is used

Postfix increment decrement in C Language

Program use increment decrement in C Language


#include <stdio.h>
int main()
{
    int x = 8;
    printf("x=%d\t", x);
    printf("x=%d\t", x++);
    printf("x=%d\t", x);
    printf("x=%d\n", x--);
    printf("x=%d\n", x);
    return 0;
}

output


x=8  x=8  x=9  x=9  x=8  

  1. Declare integer variable x = 8
  2. Initialize in integer variable x = 8
  3. printf inbuild function to display value of variable x in decimal place holder %d x = 8 for formatting tab separator \t is used
  4. printf inbuild function to display postfix increment values variable x in decimal place holder %d x = 8 for formatting tab separator \t is used
  5. printf inbuild function to display value of variable x int decimal place holder %d x = 9 for formatting tab separator \t is used
  6. printf inbuild function to display post decrement values variable x in decimal place holder %d x = 9 for formatting tab separator \t is used
  7. printf inbuild function to display value of variable x in decimal place holder %d x = 8 for formatting tab separator \t is used

How to use prefix increment decrement in C Language

Program to use prefix increment decrement in C Language


#include <stdio.h>
int main()
{
    int x = 8;
    printf("x=%d\t", x);
    printf("x=%d\t", ++x);
    printf("x=%d\t", --x); 
    printf("x=%d\n", x);
    return 0;
}

output


x=8  x=9  x=8  x=8

Steps/Description

  1. Declare integer variable x = 8
  2. Initialize in integer variable x = 8
  3. printf inbuild function to display value of variable x in decimal place holder %d = x for formatting tab separate or \t is used
  4. printf inbuild function to display prefix increment value variable x in decimal place holder %d = 9 for formatting tab separate or \t is used
  5. printf inbuild function to display variable x in decimal place holder %d = 9 for formatting tab separate or \t is used
  6. printf inbuild function to display prefix decrement x in decimal place holder %d x = 8 for formatting tab separate or \t is used
  7. printf inbuild function to display variable x in decimal place holder %d x = 8 for formatting tab separate or \t is used