Computer Science, asked by SHASHWAT909, 1 year ago

explain the increment and decrement operators with 5 example

Answers

Answered by nilesh102
2
  • Answer:-

  • The increment operator increases, and the decrement operator decreases, the value of its operand by 1.
  • The operand must have an arithmetic or pointer data type, and must refer to a modifiable data object.
  • Pointers values are increased (or decreased) by an amount that makes them point to the next (or previous) element adjacent in memory.
  • Increment and decrement operators are unary operators that add or subtract one, to or from their operand, respectively.
  • The pre-increment and pre-decrement operators increment (or decrement) their operand by 1, and the value of the expression is the resulting incremented (or decremented) value.
  • Increment operators increase the value of the variable by a particular number by which it is increased.
  • On the other hand decrement operators decrease the value of the variable by a particular number by which it was decreased, For example, i+2, i-2.
  • Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs.
  • Increment Operators are used to increased the value of the variable by one and Decrement Operators are used to decrease the value of the variable by one in C programs.
  • Both increment and decrement operator are used on a single operand or variable, so it is called as a unary operator.

  • i hope it helps you.
Answered by HariesRam
20

Increment and decrement operators are unary operators that add or subtract one, to or from their operand, respectively. ... The pre-increment and pre-decrement operators increment (or decrement) their operand by 1, and the value of the expression is the resulting incremented (or decremented) value.

Example :

The following C code fragment illustrates the difference between the pre and post increment and decrement operators:

int x;

int y;

// Increment operators

// Pre-increment - x is incremented by 1, then y is assigned the value of x

x = 1;

y = ++x; // x is now 2, y is also 2

// Post-increment - y is assigned the value of x, then x is incremented by 1

x = 1;

y = x++; // x is now 2, y is 1

// Decrement operators

// Pre-decrement - x is decremented by 1, then y is assigned the value of x

x = 1;

y = --x; // x is now 0, y is also 0

// Post-decrement - y is assigned the value of x, then x is decremented by 1

x = 1;

y = x--; // x is now 0, y is 1

❤️

Similar questions