Operators in C language

Operators One of the most important features of C is that it has a very rich set of built in operators including arithmetic, relational, logical, and bitwise operators. An operator can be any symbol like + - * / that specifies what operation need to be performed on the data. For ex: + indicates addition operation * indicates multiplication operation Operand VS Operator • An operand can be a constant or a variable. • An expression is a combination of operands and operators that reduces to a single value. For example: Consider the following expression: a+ b Here 'a' and 'b' are operand while 't' is an operator Operators & Expression are 1) Arithmetic Operators and Expressions 2) Assignment and Compound Assignment Operators 3) Increment and Decrement Operators 4) Relational Operators and Expressions 5) Logical Operators and Expressions 6) Bitwise Operators and Expressions Arithmetic Operators An arithmetic operator performs mathematical operators such as addition, subtraction, multiplication, division etc on numerical values.
Assignment Operators An assignment operator is used for assigning a value to a variable. The most common Assignment operators is e.g. to assign value 5 to the variable x: Statement is - X=5 • The statement " C = A + B " means that add the value stored in variable A and variable B then assign/store the value in variable C. += /=. *=, %= these operators are known as compound operators and it is also called shorthand notation. For Example :- X=x+ 10 ; can be replaced by "x+= 10 " Similarly for -=*/.%=, etc. Relational Operators The operators which are used to compare or to check the relation between two or more quantities.
Logical Operators The operators which act on only two logical values i.e. true and false. • ZERO(O) is always treated as FALSE • NON-ZERO value is always treated as TRUE. TRUE is always represented as 1.
Bitwise Operators These operators perform operations on each individual bit of the data value rather than the usual data value. Hence the name bitwise. These are special operators that act on char or int variables only. & Bitwise AND I Bitwise OR ^ Bitwise XOR ~ Ones Complement >> Shift Right << Shift left Increment VS Decrement operators Increment Operators: Increment Operators are the unary operators used to increment or add 1 to the operand value. The Increment operand is denoted by the double plus symbol (++). Decrement Operator : Decrement Operator is the unary operator, which is used to decrease the original value of the operand by 1. The decrement operator is represented as the double minus symbol (--). ++ and -- can be used in Preincrement/Predecrement Notation or Postincrement/Postdecrement Notation. In Preincrement/Predecrement Notation: a) The value of the variable is either incremented or decremented first b) Then, will use updated value of the variable But in Postincrement/Postdecrement Notation: a) The value of the variable is used first b) Then the value of the variable is incremented or decremented For Example :- int i, i = 2: ¡=++ j; /* preincrement: therefore i has value 3, j has value 3 * / int i, j= 2: ¡=j++: /* postincrement: therefore i has value 2, j has value 3 * /

Comments

Popular posts from this blog

Email > routers

3D printers