C programming operators
Upcoming SlideShare
Loading in...5
×
 

C programming operators

on

  • 283 views

 

Statistics

Views

Total Views
283
Views on SlideShare
283
Embed Views
0

Actions

Likes
0
Downloads
7
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

C programming operators C programming operators Document Transcript

  • C Programming Operators Operators are the symbol which operates on value or a variable. For example: + is a operator to perform addition.C programming language has wide range of operators to perform various operations.Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. C language supports following type of operators. • Arithmetic Operators • Logical (or Relational) Operators • Bitwise Operators • Assignment Operators • Misc Operators Arithmetic Operators Operator Description Example + Adds two operands A + B will give 30 - Subtracts second operand from the first A - B will give -10 * Multiply both operands A * B will give 200 / Divide numerator by denumerator B / A will give 2 % Modulus Operator and remainder of after an integer division B % A will give 0 #include<stdio.h> #include<conio.h> void main() { int a,b,c,d,e,f,g; clrscr(); printf("Enter the value of A"); scanf("%d",&a); printf("Enter the value of B"); scanf("%d",&b); c=a+b; d=a-b; e=a*b; f=a/b; g=a%b; printf("nThe Sum of A and B is%d",c); printf("nThe Sub of A and B is%d",d); printf("nThe Multiply of A and B is%d",e); printf("nThe Divide of A and B is%d",f); printf("nThe Modulus of A and B is%d",g); getch(); } Relational operators Relational operators are used to compare, logical, arithmetic and character expression. Each of these six relational operators takes two operands. Each of these
  • operators compares their left side with their right side. The whole expression involving the relation operator then evaluate to an integer. It evaluates to 0 if the condition is false and 1 if it is true. Suppose that a and b are integer variables whose values are 100 and 4, respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values. Expression Interpretation Value a<b False 0 a>b True 1 a<=b False 0 a>=b True 1 a==b False 0 a!=b True 1 Assume variable A holds 10 and variable B holds 20 then: Operator Description Example == Checks if the value of two operands is equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true. #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter the value of A:"); scanf("%d",&a); printf("Enter the value of B:"); scanf("%d",&b); printf("nThe output of A<B is%d",a<b); printf("nThe output of A>B is%d",a>b); printf("nThe output of A<=B is%d",a<=b); printf("nThe output of A>=B is%d",a>=b); getch(); }