Operator is a symbol that tells the computer to perform the mathematical and logical opeation in c programming. Operators are used in program to manipulate the data and variable. An Operator operates on variable to perform the action in a program.
Different types of Operator :
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Increment and Decrement Operator
- Conditional Operator
- Bitwise Operator
- Special Operator
1. Arithmetic Operators : An Arithemetic operator is a symbol which performs the Mathematical Operation like that Addition, Subtraction, Multiplication, Division etc. The Arithmetic operators perform between variables and consonant.
|Multiplication||*||x * y||x times y|
|Division||/||x / y||x divided by y|
|Remainder||%||x % y||remainder of x divided by y|
|Addition||+||x + y||y is added to x|
|Subtraction||-||x - y||y is subtracted from x|
2. Relational Operator : Relational operators are used to compare the values between two variables. Relational Operators Table Below....
|<=||less than or equal to|
|>=||greater than or equal to|
|!=||not equal to|
3. Logical Operator : The logical operator is used for when we want to check the condition and for making the decisions in programs.
4. Assignment operator : The assignment operator is represented by the equal sign (=). The variable appearing on the left side of = sign and it is assignment the value appearing on the right side of this sign. There are many types of assignment operator.
|+=||x+=y||x = x + y|
|-=||x-=y||x = x - y|
|/=||x/=y||x = x / y|
|%=||x%=y||x = x % y|
5. Increment and Decrement operator : The increment and decrement operators in c are represented by ++ and -- sign respectively. The operator ++ means "add by 1" and the operator -- means "subtract by 1".
6. Conditional Operator : A ternary operator pair with "? :" is available is C to construct conditional expression of the form.
Where exp1 , exp2 and exp3 are expressions.
7. Bitwise Operator : Bitwise operator is special operators which are used for manipulations of the data at bit level. These operator are used for testing the bits, or shifting them right or left. Bitwise operators may not be applied to float or double.
|^||bitwise exclusive OR|
Type Conversion is a process of converting operators of different data type into a common data type. If we use two or more different types of data items together in an expression, the c language compiler automatically carried out the conversion of the data types whenever needed.
Two types of Types Conversion.
1. Implicit type conversiont : C permits mixing of constants and variables of different types in an expression. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without losing any significance. This automatic conversion is known as implicit type conversion.
2. Explicit type conversion : C performs type conversion automatically. However, there are instances when we want to force a type conversion in a way that is different from the automatic conversion. This problem can be solved by conveting locally one of the variables to the floating point as shown :
ratio = (float)female_number/male_number
The proecess of such a local conversion is knownas explicit conversion or casting a value.
Precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator.
Associativity is the left-to-right or right-to-left order for grouping operands to operators that have the same precedence. An operator's precedence is meaningful only if other operators with higher or lower precedence are present. Expressions with higher-precedence operators are evaluated first.
Table of Associativity below...
|Function expression||()||Left to Right|
|Array expression||||Left to Right|
|Structure operator||->||Left to Right|
|Structure operator||.||Left to Right|
|Unary Minus||-||Right to Left|
|Increment/Decrement||++/--||Right to Left|
|One's Complement||~||Right to Left|
|Negation||!||Right to Left|
|Address of||&||Right to Left|
|Value of address||*||Right to Left|
|Type case||(type)||Right to Left|
|Size in bytes||sizeof||Right to Left|
|Multiplication||*||Left to Right|
|Division||/||Left to Right|
|Modulus||%||Left to Right|
|Addition||+||Left to Right|
|Subtraction||-||Left to Right|
|Left Shift||<<||Left to Right|
|Right Shift||>>||Left to Right|
|Less than||<||Left to Right|
|Less than or Equal to||<=||Left to Right|
|Greater than||>||Left to Right|
|Greater than or Equal to||>=||Left to Right|
|Equal to||==||Left to Right|
|Not Equal to||!=||Left to Right|
|Bitwise AND||&||Left to Right|
|Bitwise exclusive OR||^||Left to Right|
|Bitwise OR|||||Left to Right|
|Logical AND||&&||Left to Right|
|Logical OR||||||Left to Right|
|Conditional Operator||? :||Right to Left|
|Assignment Operator||= , +=, -=, *=, /=, %=,^=, !=, <<=,>>=||Right to Left|
|Comma||,||Right to Left|
Welcome Guys.. What is loop and how many types of loops in c programming language. How loops work in c programming language.