Note
Note
operators in C are symbols that represent operations to be performed on data. They are used to
manipulate values, perform calculations, and make decisions in a program. Here are some of the
basic operators in C:
1. Arithmetic Operators:
‘=’ (Assignment): Assigns the value of the right operand to the left operand.
‘+=’ (Addition Assignment): Adds the right operand to the left operand and assigns the result
to the left operand.
‘-=’ (Subtraction Assignment): Subtracts the right operand from the left operand and assigns
the result to the left operand.
‘*=’ (Multiplication Assignment): Multiplies the left operand by the right operand and
assigns the result to the left operand.
‘/=’ (Division Assignment): Divides the left operand by the right operand and assigns the
result to the left operand.
‘%=’ (Modulus Assignment): Calculates the modulus of the left operand with the right
operand and assigns the result to the left operand.
Loop:
In programming, a loop is used to repeat a block of code until the specified condition is met.
for loop
while loop
do...while loop
This process goes on until the test expression is false. When the test expression is false, the loop
terminates.
while (testExpression) {
The while loop evaluates the testExpression inside the parentheses ().
If testExpression is true, statements inside the body of while loop are executed.
Then, testExpression is evaluated again.
The process goes on until testExpression is evaluated to false.
If testExpression is false, the loop terminates (ends).
Flowchart of while loop
The do..while loop is similar to the while loop with one important difference. The body of do...while loop
is executed at least once. Only then, the test expression is evaluated.
do {
while (testExpression);
The body of do...while loop is executed once. Only then, the testExpression is evaluated.
If testExpression is true, the body of the loop is executed again and testExpression is evaluated
once more.
This process goes on until testExpression becomes false.
If testExpression is false, the loop ends.
If ( test expression )
// code
The if statement evaluates the test expression inside the parenthesis ().
If the test expression is evaluated to true, statements inside the body of if are executed.
If the test expression is evaluated to false, statements inside the body of if are not executed.
C if……else statement :
if ( test expression )
else
C if……else Ladder:
The if...else statement executes two different codes depending upon whether the test expression is true
or false. Sometimes, a choice has to be made from more than 2 possibilities.
The if...else ladder allows you to check between multiple test expressions and execute different
statements.
if ( test expression 1)
// Statement (s)
{
// Statement (s)
// Statement (s)
else
// Statement (s)
Nested if...else:
Nested if statement:
The ANSI standard specifies that 15 levels of nesting must be supported. In C, an else statement always
refers to the nearest if statement in the same block and not already associated with if.