Computer Science, asked by anamik59, 9 months ago

Differentiate between unary increment operator and unary decrement operator. need 3 difference​

Answers

Answered by syedashiq2005
3

Increment Operators: The increment operator is used to increment the value of a variable in an expression. In the Pre-Increment, value is first incremented and then used inside the expression. Whereas in the Post-Increment, value is first used inside the expression and then incremented.

Syntax:

// PREFIX

++m

// POSTFIX

m++

where m is a variable

Example:

#include <stdio.h>

int increment(int a, int b)

{

a = 5;

// POSTFIX

b = a++;

printf("%d", b);

// PREFIX

int c = ++b;

printf("\n%d", c);

}

// Driver code

int main()

{

int x, y;

increment(x, y);

return 0;

}

Decrement Operators: The decrement operator is used to decrement the value of a variable in an expression. In the Pre-Decrement, value is first decremented and then used inside the expression. Whereas in the Post-Decrement, value is first used inside the expression and then decremented.

Syntax:

// PREFIX

--m

// POSTFIX

m--

where m is a variable

Example:

#include <stdio.h>

int decrement(int a, int b)

{

a = 5;

// POSTFIX

b = a--;

printf("%d", b);

// PREFIX

int c = --b;

printf("\n%d", c);

}

// Driver code

int main()

{

int x, y;

decrement(x, y);

return 0;

}

Similar questions