0% found this document useful (0 votes)
27 views3 pages

Operators in C

Operators are used to perform mathematical and logical operations in C programming. The common operators include arithmetic, relational, logical, conditional, assignment, and increment/decrement operators. Arithmetic operators are used for basic math operations. Relational operators compare values and return true or false. Logical operators combine expressions. The conditional operator selects between expressions based on a condition.

Uploaded by

dhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Operators in C

Operators are used to perform mathematical and logical operations in C programming. The common operators include arithmetic, relational, logical, conditional, assignment, and increment/decrement operators. Arithmetic operators are used for basic math operations. Relational operators compare values and return true or false. Logical operators combine expressions. The conditional operator selects between expressions based on a condition.

Uploaded by

dhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Operators:(10 Marks)

* Operators are mathmetical Symbols used to write expressions.


* Expressions are written by using operator and operands
10+20
10,20 => are called as Operands
+ => is called as Operator.

* If an operator having only operand is called as Unary operator.


-20

* If an operator having two operands is called as Binary Operator.


10+20

* If an operator having three operands is called as Ternary operator.

* C supports the following operators

1.Arithmetic Operators (+,-,*,/,%)


2.Relational Operators (<,<=,>,>=,==,!=)
3.Logical Operators (&&(and),||(or),!(not))
4.Conditional operator(?:)
5.Assignment operator(=)
6.Increment and Decrement Operators(++,--)
7.Bitwise Operators(&,|,^,~,<<,>>)
8.Special Operators

Arithmetic Operators:
* These operators are used to perform Arithmetic operations such as
addition,subtraction,etc.
Operator Meaning Expression
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b (Quotient)
% Modulus Divsion a%b (Reminder)

Relational Operators:
* These operators are also called comparision Operators
* Used to compare two values and result will be either true or false.

Operator Meaning Expression


< Lessthan a<b
<= Lessthan or Equals to a<=b
> Greaterthan a>b
>= GreaterThan or equals to a>=b
== Equals to a==b
!= Not Equals to a!=b

Logical Operators:
* These operators are used to combine two expressions.
1.Logical AND(&&)
2.Logical OR (||)
3.Logical NOT(!)
1.Logical AND(&&):
* Return true when two expressions are true.
* Return false when one of the expression is false.
Truth Table:
Exp1 Exp2 Exp1 && Exp2
True True True
True False False
False True False
False False False
2.Logical OR(||):
* Return false when two expressions are false.
* Return true when one of the expression is true.
Truth Table:
Exp1 Exp2 Exp1 || Exp2
True True True
True False True
False True True
False False False

3.Logical NOT (!)


* It will convert true into false and false into true.
ex:
Exp !Exp
True False
False True

Conditional Operator:
* The purpose of conditional operator is to test a condition and select
either true or false statement.
* This operator is denoted by using ?:
* ? is used to test a condition.
* : is used to saperate true and false statements.

syntax:
(condition)?true-statement:false-statement;

if condition is true, it will select true-statement


if condition is false,it will select false-statement
ex:
(a>b)?printf("A is big"):printf("B is big");

case 1:
a=10,b=20
10>20 => false => B is big

case 2:
a=12, b=5
12>5 => true => A is big

Assignment Operator:
* This operator is used to assign a value to a variable.
* This operator is denoted by using =
* you can store value directly into a vairable.
syntax:
variablename=value;
ex:
int x=20;

* you can assign the value of variable to another variable.


syntax:
variablename=variablename;
ex:
int x=20;
int y=x;
* You can also assign an expression to a variable.
ex:
int a=20;
int b=30;
int sum=a+b;

Increment and Decrement Operators:


* Increment means adding 1 to a variable.
* Decrement means subtracting 1 from a variable.
* Increment is denoted by using ++
* Decrement is denoted by using --
x=x+1 => x++
x=x-1 => x--
ex:
int x=10;
x++; // x=11
x--; // x=10

Pre-Increment -> ++variable;


Post-Increment -> variable++;
Pre-Decrement -> --Variable;
Post-Decrement -> variable--;

You might also like