Looping in C Programming Language

 Looping in C Programming Language Use: When we want to perform specific task repeatedly then we can use looping. In C Language there are three type of loop: For Loop While Loop Do while Loop Nested for Loop Each Loop statement requires three things: Initialization  Test Condition Increment/Decrement Operation 1. For Loop: For Loop is a repetition control structure which allow us to write a loop that is executed a specific number of time. Syntax:               for( initialization ; test condition; increment/decrement operation)                 {                    ------                    body of for loop;                    ------               } 2. While Loop: While Loop is use to per to p...

Operators in C Program

 Operator in C Programming Language


Operators is one of the TOKEN which is use to perform specific operations on different values/operands. Like arithmetic, relational, assignment etc...

C Program support eight (8) operators:

  1. Arithmetic Operator
  2. Assignment Operator
  3. Relational Operator
  4. Conditional Operator
  5. Increment and Decrement Operator
  6. Logical Operator
  7. Bitwise Operator
  8. Special Symbol Operator

1. Arithmetic Operator:
   

  • Arithmetic operators are used to perform arithmetic operations like... +, -, *, /, % .
    • Real Arithmetic:
      • when we perform arithmetic operations on real numbers, answer will be in real number.
      • Example:
        • 12.5/6.5 =  1.9230
    • Mix Mode Arithmetic:
      • When we perform arithmetic operations on those numbers in which some numbers are integer and some are real then answer will be floating number.
      • Example:
        • 12+3.5 = 15.5

2. Relational Operators:
  • When we want to compare two operands or values, we use relational operators.
  • Relational operator represent relation between two operands.
  • There are six relational operators.
  • Relational operators are used in conditional statement like if-else and looping statements like for, while or do while.

3. Assignment Operators:
  • When we want to assign any value operand or expression to any variable then we can use assignment operators(=).
  • Syntax:
    • variable_name   OP    value/operand/expression
    •  Example:
      • a=5;
      • a=(x+y+z);
  • Short Hand Assignment Operator:
    • a=a+1  -->  a+=1
    • a=a*1  -->  a*=1
    • a=a-b  -->  a-=b
    • a=a/5  -->  a/=5
    • x=x*(n+1)  -->  x*=(n+1)
    • x=x+(n*m-o)  -->  x+=(n*m-o)
  • When same operand is use at left hand side and right hand side of assignment operator in any equation, then short hand assignment operator can be used.
  • Syntax:
    • Variable_name   OP   = expression.

4.Logical Operators:
  • Logical operator is used to check multiple conditions and make decision.
  • There are three logical operators:
    • Logical AND (&&)
    • Logical OR (||)
    • Logical NOT (!)
  • LOGICAL AND:
    • Logical AND operator check all conditions if all conditions are throw then only true block will be executed.
    • If only any one condition is false then false block will be executed and it will return (0).
                                     LOGICAL AND TABLE


  • LOGICAL OR:
    • Logical OR operator check all condition if any one condition is true then it will return 1.
                                    LOGICAL OR TABLE


  • LOGICAL NOT:
    • Logical NOT operator give reverse result of given condition.
    • If condition is false then it will return 1 (true).
    • If condition is true then then it will return 0 (false).


5. Conditional Operator: (? :)
  • Ternary operator ? and : are used to give condition in following expression.
  • exp1 (condition)  ?  exp2(if condition is true)  :  exp3(else false)
  • In this expression, exp1 is true then exp2 will be assigned to variable.
  • If exp1 is false then exp3 will be assigned to variable.

6. Increment Decrement Operator:
  • Increment Decrement operator are used to increment or decrement a value by 1.
  • This operator is use in looping statement.
  • There are two increment operators:
    • Post Increment Operator : a++
    • Pre Increment Operator : ++a
  • There are also two decrement operators:
    • Post Decrement Operator : a--
    • Pre Decrement Operator : --a
7.Bitwise Operator:
  • Bitwise operator are use to perform operations on bits.
  • Mainly there are 5 bitwise operators:
    1. & bitwise AND
    2. | bitwise OR
    3. ^ bitwise XOR
    4. << shift left
    5. >> shift right
  1. & bitwise AND:
    • If both bits are 1 there only answer will be 1 otherwise answer will be 0.
    • & bitwise AND Table
  2. | bitwise OR:
    • If value of any 1 bit is 1 then if value of answer will be 1, otherwise will be 0.
    • | bitwise OR Table


  3. ^ bitwise XOR:
    • If both bits are opposite then only answer will be 1 otherwise answer will be 0.
    •  ^ bitwise XOR Table


  4. << shift left:
    • Shift left operation use to move number of bits position from left hand side.
  5. >> shift right:
    • Shift right operation is use to move number of bits position from right hand side.
8. Special Operators:
  • There are different special operator are as follows:
    • , (comma) operators
    • Size of operators
    • Pointer operators (*,&)
    • Pointer member operators (->) etc.

Comments

Popular posts from this blog

Data Types in C Program

Different Modules to solve the program/problem