programming hubby -tutorial4u
3 min readAug 21, 2020

--

about if if-else and conditional operator (AND&&,OR||, NOT! ) in programming language

DECISION CONTROL CONTROL INSTRUCTION

A decision control instruction can be i mplemented in c language.
1) The if statement
2) The if-else statement
3) The conditional statement
Now we understand each one topic separately.

structure of if statement

than execute this statement.
if(the condition is true)

What this expression says is “
The keyword if tells the compiler that what follows the keyword is a decision control structure instruction. The condition following the keyword if is always enclosed within a pair of parentheses.if the condition, whatever it is ,is true ,then the statement is executed .
if the condition is not true,then the statement is not executed.instead the program skips past it. But how do we express a condition using C’s ‘relational’ operators. The relational operator allow us to compare two values to see whether they are equal to each other ,unequal or whether one is grater than the other. Here’s how they look and how evaluated in c programming language.
the expression is true if
X==Y X is equal to Y
Y!=X X is not equal to Y
X>Y X is grater than Y
X<=Y X is less than or equal Y
X>=Y X is grater than or equal to Y.
The relational operator should be familiar to you except for the equality operator== and the inequality operator != . note that ‘=’ is used for assignment,where ,== is used for comparison of two quantities.

It may so happen that in a program we want more than one statement to be executed if the expression following if is satisfied.
If such multiple statement are to be executed , then they must be placed within a pair of braces.

The if statement by itself will executed a single statement, or a group of statement, when the expression following if evaluates to true .it does nothing when the expression evaluates to false.Can we execute one group of statement if the expression evaluates to true and another group of statements if the expression evaluates to false?
MULTIPLE STATEMENT WITHIN C
It is perfectly all right if we write an entire if-else construct within either the body of the if statement or the body of an else statement.
This is called ‘nesting ‘ of ifs.

C allows usage of three logical operator , namely, &&,||, and !
these are to be read as ‘AND’ ‘OR’ and ‘NOT’ respectively. In electronics language these are known as gate.
There are several things to note about these logical operator. Most obviously , two of them are composed of double symbols: || and &&. don’t use the single symbol | and &. These single symbols also have meaning, They are bit wise operators. The first two operator ,&& and ||, allow to or more conditions to be combined in an if statements.

So far we have use only the logical operator is the NOT operator, written && and ||. The third logical operator reverse the result of the expression evaluates to a non zero value, then applying ! operator to it makes it 1 is considered to be false or true respectively. Here is an example of the NOT operator applied to a relational expression. ex: !(y<10 font=””>10>

USE OF LOGICAL OPERATOR
The conditional operator ? and : are sometimes called ternary operators since they take three arguments . In fact , They form a kind of for shortened if then else. their general form is,

OPERATOR TYPE
! logical not
* / % arithmetic and modulus
+ — arithmetic
<> <=, >= relational THE CONDITIONAL OPERATOR
== != relational
&& logical AND
expression 1 ? expression 2 : expression 3
= assignment if expression 1 is true (that is, if its value is non zero) then the value returned will be expression 2. otherwise the value returned will be expression 3.”
HIERARCHY OF OPERATORS REVISITED

Originally published at https://programminghubby.blogspot.com.

--

--