Monday, May 02, 2016

Operator in c

Operators in C. What is the use of Operators in C. In Our Daily life we perform different types of Operations like Addition,Subtraction, Multiplication,Division etc.For calculating or performing our required operation we want particular operator. In the same manner while writing program in c we have different types of operators to perform operations as our or user requirement for that pupose we are using Operator.

If You learn C Language yo no need learn basics of C++,java,C#.net because all the programming languages features are derived from C language only


In Previous Post we learn What is Data Type and How many Data types in c- language. In this lesson we learn Operators in C-Language. C Supports set of operators. Operators are used in programs to manipulate data and variables. They usually form a part oof the mathematical of logical expressions. C operators are can be divided into a number of types. They include:

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

ARITHMETIC OPERATORS


C Provides all the basic arithmetic operators. they are listed in Below. the operators +,-,*,/ all work the same way as they do in other languages.
Operator Meaning
+ Addition or unary plus
- Substraction or unary minus
* Multiplication
/ Division
% Modulo Division
Ex: a+b,a-b,a/b,a%b..

RELATIONAL OPERATORS


We often compare two variables, and depending on their relation,take certain decisions. For example we may compare age of two persons, or the price of two items, and so on.These comparisons can be done with the help of Relational Operators.The following are the relational operators in c-language.
Operator Meaning
< is Lessthan
<= is Less than or equal to
> is Greater than
>= is Greater than or equal
== is Equal to
!= is Not equal to
Ex: a==b,

LOGICAL OPERATORS


C has the following three logical operators.
  • && meaning logical AND
  • || meaning logical OR
  • ! meaning logical NOT
The logical operators &&and || are used when we want to test more than one condition and make decisions. Ex: a>b&&x==10. Here we mention Truth table for Logical And operation
a b a&&b
T T T
T F F
F T F
F F F

ASSIGNMENT OPERATOR

Assignment operators are used to assign the result of an expression to a variable. We have seen the usual assignment operator, '='. Ex: a=a+b, a=b-c,a+=b.

INCREMENT AND DECREMENTS OPERATORS


Increment Operator increases the value of variable by 1. There are two types of Increment Operators.
  1. Pre Increment Operator
  2. Post Increment Operator
Pre Increment Operator:First Increased the value of a variable and it used that value. Ex:a=5; a=++a; a=1+5; a=6; Post Increment Operator: First uses the value and increased that value by 1. Ex: a=5; a=a++; a=5+1; a=6; Decrement Operator: This operator is used for decrease the value by 1.There are two types of Decrement Operators.
  1. Pre Decrement operator
  2. Post Decrement Operator
Pre Decrement Operator:First decreses the value by 1 and used that value to the variable. Ex:a=10; a=--a; a=1-10; a=9; Post Decrement Operator:First assign the value and then decreses that value by 1. Ex: a=10; a=a--; a=10-1; a=9;

Conditional Operator


This operators are used to perform the condition and point the values in the statement itself.
  Syntax: exp 1? exp2:exp3; where exp1, exp2, and exp3 are expressions. The operator ? : works as follows. exp1 is evaluated first. If it nozer(true)then the exp2 is evaluated and becomes the value of the expression. If exp1 is false,exp3 is evaluated and its value becomes the value of the expression. Note that only one of the expressions either exp2 or exp3) is evalulated.
 Ex: a=10; b=15; x=(a.b)?a:b; in this example, x will be assigned the value of b. this can be acheived by using the if.else statements as follows.
if(a>b)
 x=a;
 else
 x=b;

BITWISE OPERATOR


In C language Bitwise operators is used for manipulation of data at bit level.These operators are used for testing the bits, or shifting them right or left.Bit wise operators are may not be applied to floator double.
Operator Meaning
& bitwise AND
| bitwise OR
^ bitwise exclusive OR
<< shift left
>> Shift Right
~ one's complement

SPECIAL OPERATOR


C supports some special operators of interest such as comma, size of operators .

The comma operator

The comma operator can be used to link the related expressions together. A comma-linked list of expresions are evaluted left to right and the value of right-most expression is the value of the combined expression. Ex: value=(x=10,y=5,x+y); First assign the values 10 to x,then assign 5 to y, and finally assign15(i.e 10+5) to value.since comma operator has the lowest precedence of all operators.

The size of operator

The size of is a compile time operator and when used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, a constant or data type qualifier. The size of operator is normally used to determine the length of arrays and structures when their sizes are not known to the programmer. Ex:m=sizeof(sum); n=sizeof(long int);

2 comments:

  1. Kids educational toys serve a much larger purpose besides simply giving your child something to play with, and keeping the out of your hair. Kids educational toys do just that; they create opportunities for your child to grow mentally, and to learn tools and functioning skills that they will need to call upon for their success as an adult. As a matter of fact, this is the main reason why parents want their children to have educational toys.academic writing

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete