0% found this document useful (0 votes)
30 views

Conditional Operator

The conditional operator (? :) is a ternary operator that takes three operands and evaluates to either the second or third operand depending on whether the first operand evaluates to true or false. Increment and decrement operators increase or decrease a variable's value by one and have higher precedence than other operators. Pre-increment operators increment the variable before it is used in an expression while post-increment operators increment after.

Uploaded by

Pirzada Swati
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Conditional Operator

The conditional operator (? :) is a ternary operator that takes three operands and evaluates to either the second or third operand depending on whether the first operand evaluates to true or false. Increment and decrement operators increase or decrease a variable's value by one and have higher precedence than other operators. Pre-increment operators increment the variable before it is used in an expression while post-increment operators increment after.

Uploaded by

Pirzada Swati
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Conditional operator

• The conditional operator (? :) is a ternary operator (it takes


three operands). Theconditional operator works as follows:
The first operand is implicitly converted to bool . ... If the first
operand evaluates to false (0), the third operand is evaluated
if(y < 10) var = (y < 10) ? 30 : 40;
{
var = 30;
}
Else
{
var = 40;
}
• #include <iostream>
• using namespace std;
• int main()
• {
• int i = 1, j = 2;
• cout << ( i > j ? i : j ) << " is greater." << endl;
• }
Increment and Decrement
Operator
• 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. Unary
operators are having higher priority than the other operators
it means unary operators are executed before other operators
Type of Increment Operator
• pre-increment
• post-increment
• prefix-increment (++ variable)
• In pre-increment first increment the value of variable and then
used inside the expression (initialize into another variable)
• postfix-increment (variable ++)
• In post-increment first value of variable is used in the
expression (initialize into another variable) and then
increment the value of variable.
Prefix
-increment
• #include<iostream.h>
• #include<conio.h>
• void main()
• {
• int x,i;
• i=10;
• x=++i;
• Cout<<"x:“<<x;
• Cout<<"i: “<<i;
• getch();
• }
• Output:
• x: 11 i: 11
• #include<iostream.h>
• #include<conio.h>
• void main()
• {
• int x,i; i=10; x=i++;
• Cout<<"x:“<<x;
• cout<<"i:“<<i;
• getch();
• }
• Output:
• x: 10 i: 11
• assignment expressions (*=, /=, +=, -=)

You might also like