












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A detailed explanation of various operators in C programming language. It covers arithmetic, relational, equality, logical, unary, conditional, and bitwise operators. Each operator is explained with its meaning, syntax, and example. The document also includes information on type conversion and type casting.
Typology: Assignments
1 / 52
This page cannot be seen from the preview
Don't miss anything!













































1
OPERATORS IN C
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions.
Operands are expressions or values on which an operator operates or works (often constants or variables)
(1) ARITHMETIC OPERATORS
OPERATION OPERATOR SYNTAX COMMENT RESULT Multiply * a * b result = a * b 27 Divide / a / b result = a / b 3 Addition + a + b result = a + b 12 Subtraction - a - b result = a – b 6 Modulus % a % b result = a % b 0
Value of a=9, b=
(2) Relational Operators (>, >= , < , <= )
It is Also known as a comparison operator, It is an operator that compares two values. Expressions that contain relational operators are called relational expressions. Relational operators return true or false value, depending on whether the conditional relationship between the two operands holds or not.
(2) Relational Operators (>, >= , < , <= ) number :For example : Check whether first number is greater than second Void main() { int x = 5 , y = 3; Clrscr(); if (x > y) printf(“\n x is greater than y”); else printf(“\n y is greater than x “); getch(); }
(3) Equality Operators (== , != )
OPERATOR MEANING == RETURNS OTHERWISE 1 IF BOTH OPERANDS ARE EQUAL, 0 != RETURNS 1 IF OPERANDS DO NOT HAVE THE SAMEVALUE, 0 OTHERWISE
(4) Logical Operators (&& , || ,! )
Dr.Ashwin Dobariya
11
&& (AND) Operator If (condition1 && condition2 ) True part else False Part Expression 1 / Condition
Expression 2 / Condition
Result True True True True False False False True False False False False
|| (OR) Operator If (condition1 || condition2) True part else False Part Expression 1 / Condition
Expression 2 / Condition
Result True True True True False True False True True False False False
(4) Logical Operators (&& , || ,! ) [Passing marks 40 out of 100]For example 2 : Input five subject marks and check whether student is pass or fail using AND and OR operator. void main( ) { int s1,s2,s3,s4,s5,tot,per; clrscr(); printf scanf(“(“%d%d%d%d%\n Enter marks of five subjects :d”,&s1,&s2,&s3,&s4,&s5);”); tot = s1 + s2 + s3 + s4 + s5; per = tot / 5.0; // Using AND Operator if(s1 >=40 && s2 >= 40 && s3 >= 40 && s4 >=40 && s5>=40 ) else^ printf(“\n Result is^ Pass”); // Using OR Operator^ printf(“\n Result is^ Fail”); if(s1 < 40 || s2 <40 || s3 < 40 || s4 < 40 || s5 < 40 ) printf(“\n Result is Fail ”); else printf(“\n Result is Pass”);
}^ getch ( ) ;
(5) Unary Operators (++ , -- , - ) A operator which operates on a single operand , is known as unary operator. C language supports three unary operators. (1) minus ( - ) , (2) increment (++) (3) decrement (--) operators. When an operand is preceded by a minus sign, the unary operator negates its value. E.g int x = - The increment operator is a unary operator that increases the value of its operand by 1. For example : int x = 5; // To increment by 1 value in x x = x + 1 OR x ++ OR x += 1 Similarly, the decrement operator decreases the value of its operand by 1. For example, For example : int x = 5; // To decrement by 1 value in x x = x - 1 OR x - - OR x -= 1
Dr.Ashwin Dobariya
(prefix / postfix) Increment & Decrement Operators
16
Y = X++
Y = X
X = X + 1
Y = X++
Y = X Y = 5
X=5+1 X = 6
First Assignment Process
SecondIncrement
(6) Conditional Operators (? : )
(6) Conditional Operators (? : )
printf(“\n Enter any two numbers “);
shiftright**^ LefttoRight