conditional operators in c programming |
Conditional operators in c programming
Hello friends,
Today, we will learn about the conditional operators by moving this C programming language tutorial. Before that it is necessary to know about "use of if-else statement". For this you have to click on use of if-else statement and you reach on my previous post where i have covered all about 'if-else statement in decision control'.
Then let's start today's topic which is 'conditional operators'.
What is conditional operators
Conditional operators are used to check the condition. This operator has only two options TRUE and FALSE. If the given condition satisfies, then TRUE will return otherwise FALSE will be return.
This operator is known by two names.
Ternary Operator
The : operator
It is actually if condition but it has been modified slightly and a short form has been created which can provide only two options. TRUE and FALSE
Syntax of conditional operators
Condition? True Expression: False Expression;
Some important information about conditional operators
- Question mark "?" Represents if part.
- condition part gives us either one or both types of value.
- If the condition part returns true value, then true expression will be executed. That is, the expression on the left side of ":" will execute.
- If the condition part returns false value then False expression will be executed. That is, the expression on the right side of ":" will execute.
Now lets see some examples to understand conditional operators
Example. 1
Output
If you enter any number which is greater then 0 then it execute positive otherwise negative number.
Example. 2
Output
In this program, you enter any two number and computer tell you which number is greater
Example. 3
Output
In this program, if you enter any number which is greater then 18 then it give output 'you are eligible to vote' otherwise it show 'you are not eligible to vote'
I hope that you have understood the operators well. If there are any quarry then you can comment me on comment box
Thanks for reading this post
Also read
0 Comments
Please do not enter any spam link in the comment box and please follo me.