C Increment and Decrement Operators - learnit

Home Top Ad

Post Top Ad

Saturday, April 24, 2021

C Increment and Decrement Operators

C Increment and Decrement Operators

C Programming

C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on. This makes C++ powerful as well as flexible.


Why Learn C++

-C++ is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance.


-After learning C++, it will be much easier to learn other programming languages like Java, Python, etc.


-C++ helps you to understand the internal architecture of a computer, how computer stores and retrieves information


C Increment and Decrement Operators

Increment Operators

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
++i
// POSTFIX
i++

Where i is a variable

Example

#include<stdio.h>
#include<conion.h>
int main()
{
int i=10;
i++; // increment
printf ("Value is I=%d",i);
}
Output
Value is i=11


Decrement Operators

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
--i
// POSTFIX
i--

Where i is a variable

Example

#include<stdio.h>
#include<conion.h>
int main()
{
int i=10;
i--; // Decrement
print ("Value is I=%d",i) ;
}
Output
Value is i=9

Increment Operators Decrement Operators
Increment Operator adds 1 to the operand Decrement Operator subtracts 1 from the operand
Postfix increment operator means the expression is evaluated first using the original value of the variable and then the variable is incremented(increased) Postfix decrement operator means the expression is evaluated first using the original value of the variable and then the variable is decremented(decreased)
Prefix increment operator means the variable is incremented first and then the expression is evaluated using the new value of the variable Prefix decrement operator means the variable is decremented first and then the expression is evaluated using the new value of the variable
Generally, we use this in decision making and looping This is also used in decision making and looping

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad