Increment and Decrement Operators in C#


Increment operator increases integer value by one i.e.

int a = 10;
a++;
++a;

Decrement operator decreases integer value by one i.e.

int a = 20;
a--;
--a;

The following is an example demonstrating increment operator −

Example

 Live Demo

using System;

class Program {
   static void Main() {
      int a, b;

      a = 10;
      Console.WriteLine(++a);
      Console.WriteLine(a++);

      b = a;
      Console.WriteLine(a);
      Console.WriteLine(b);
   }
}

Output

11
11
12
12

The following is an example demonstrating decrement operator −

int a, b;
a = 10;

// displaying decrement operator result
Console.WriteLine(--a);
Console.WriteLine(a--);

b = a;
Console.WriteLine(a);
Console.WriteLine(b);

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements