OPERATORS IN C
WHAT IS OPERATOR? • C support rich set of built-in operators. • We have already used several of them, such as + - * & = < etc. • Operators are used in programs to manipulate data and variables. • An operator is a symbol that perform certain mathematical or logical manipulations. • C operators can be classified into number of categories.
TYPES OF OPERATORS • Arithmetic operators • Relational operators • Logical operators • Assigment operators • Increment and decrement operators • Conditional operators • Bitwise operators • Special operators
ARITHMETIC OPERATORS • C provides all the basic arithmetic operators. • Arithmetic operators are addition(+),Subtraction(),Multiplication(*),Division(/) and Modulo division(%). • For example : a +b a-b a*b a/b
• There are 3 types of arithmetic operator 1.Integer arithmetic(When both operands are single arithmetic expression) ex: 5 + 5 = 10. 2.Real arithmetic(An arithmetic operation involving only real operands ) ex : 6.0/7.0=0.857143 3.Mixed-mode arithmetic(When one of the operands is real and the other is integer) ex: 15/10.0 = 1.5
RELATIONAL OPERATORS • Relational operator compares two quantities depending on their relation. • For example : compare the age of two persons,prices of two items and so on. • Relational operator : Greater than(>), Greater than or equal to(>=), Less than(<), Less than or equal to(<=), Equal to(==),Not equal to(!=). Eg: 10 < 20 a ==b
LOGICAL OPERATORS • Logical operator which combines two or more relational expressions,is termed as compound logical expression. • C has the following three logical operator. && - Logical AND || - Logical OR ! - Logical NOT For example : if(age>55 && salary<1000)
ASSIGNMENT OPERATORS • Assignment operators are used to assign the result of an expression to a variable. = -> Assignment operator Example : a=5; • C has a set of ‘Shorthand’ assignment operator. v op=exp Example : x += 3;
INCREMENT AND DECREMENT OPERATORS • The increment operator ++ adds 1 to the operand, while the decrement operator - - subtracts 1 to the operand. ++ - Increment operator -- - Decrement operator • We use the increment and decrement statements in for and while loops. ++m; or m++; --m; or m--;
CONDITIONAL OPERATORS • A ternary operator pair “?:” is available in c, the conditional expression of the form exp1 ? exp2 : exp3 • Where exp1,exp2,exp3 are expressions. • exp 1 is evaluated first, if it is true then exp 2 is executed. • If exp 1 is evaluated , it is false then exp3 is executed. a=10; b=15; x=(a>b)?a : b; • It can be achieved using if…else statements.
BITWISE OPERATORS • C has a distinction of supporting special operators known as bitwise operator for manipulating of data at bit level. • These operator are used for testing the bits or shifting them right or left. & - bitwise AND | - bitwise OR <<- shift left >>-shift right
SPECIAL OPERATORS • C supports some special operators such as comma operator , sizeof operator. • Comma operator : The comma operator used to link the related expression together. For example : for(n=1,m=10,n<=m;n++,m++); • Sizeof operator : Sizeof operator is a compile time operator, it returns the number of bytes the operand occupies. For example : m=sizeof(sum);

OPERATORS IN C.pptx

  • 1.
  • 2.
    WHAT IS OPERATOR? •C support rich set of built-in operators. • We have already used several of them, such as + - * & = < etc. • Operators are used in programs to manipulate data and variables. • An operator is a symbol that perform certain mathematical or logical manipulations. • C operators can be classified into number of categories.
  • 3.
    TYPES OF OPERATORS •Arithmetic operators • Relational operators • Logical operators • Assigment operators • Increment and decrement operators • Conditional operators • Bitwise operators • Special operators
  • 4.
    ARITHMETIC OPERATORS • Cprovides all the basic arithmetic operators. • Arithmetic operators are addition(+),Subtraction(),Multiplication(*),Division(/) and Modulo division(%). • For example : a +b a-b a*b a/b
  • 5.
    • There are3 types of arithmetic operator 1.Integer arithmetic(When both operands are single arithmetic expression) ex: 5 + 5 = 10. 2.Real arithmetic(An arithmetic operation involving only real operands ) ex : 6.0/7.0=0.857143 3.Mixed-mode arithmetic(When one of the operands is real and the other is integer) ex: 15/10.0 = 1.5
  • 6.
    RELATIONAL OPERATORS • Relationaloperator compares two quantities depending on their relation. • For example : compare the age of two persons,prices of two items and so on. • Relational operator : Greater than(>), Greater than or equal to(>=), Less than(<), Less than or equal to(<=), Equal to(==),Not equal to(!=). Eg: 10 < 20 a ==b
  • 7.
    LOGICAL OPERATORS • Logicaloperator which combines two or more relational expressions,is termed as compound logical expression. • C has the following three logical operator. && - Logical AND || - Logical OR ! - Logical NOT For example : if(age>55 && salary<1000)
  • 8.
    ASSIGNMENT OPERATORS • Assignmentoperators are used to assign the result of an expression to a variable. = -> Assignment operator Example : a=5; • C has a set of ‘Shorthand’ assignment operator. v op=exp Example : x += 3;
  • 9.
    INCREMENT AND DECREMENTOPERATORS • The increment operator ++ adds 1 to the operand, while the decrement operator - - subtracts 1 to the operand. ++ - Increment operator -- - Decrement operator • We use the increment and decrement statements in for and while loops. ++m; or m++; --m; or m--;
  • 10.
    CONDITIONAL OPERATORS • Aternary operator pair “?:” is available in c, the conditional expression of the form exp1 ? exp2 : exp3 • Where exp1,exp2,exp3 are expressions. • exp 1 is evaluated first, if it is true then exp 2 is executed. • If exp 1 is evaluated , it is false then exp3 is executed. a=10; b=15; x=(a>b)?a : b; • It can be achieved using if…else statements.
  • 11.
    BITWISE OPERATORS • Chas a distinction of supporting special operators known as bitwise operator for manipulating of data at bit level. • These operator are used for testing the bits or shifting them right or left. & - bitwise AND | - bitwise OR <<- shift left >>-shift right
  • 12.
    SPECIAL OPERATORS • Csupports some special operators such as comma operator , sizeof operator. • Comma operator : The comma operator used to link the related expression together. For example : for(n=1,m=10,n<=m;n++,m++); • Sizeof operator : Sizeof operator is a compile time operator, it returns the number of bytes the operand occupies. For example : m=sizeof(sum);