SlideShare a Scribd company logo
Operators
PRESENTED BY : MR. MADHUR THAPLIYAL
ASSISTANT PROFESSOR
SCHOOL OF COMPUTING
DEPARTMENT OF COMPUTER APPLICATIONS
Definition
 Operators in c are used to perform operations on variables and
values.
In example below we used + operator to add together two values:
int myNum = 100+50;
Although the + operator is also used to add together two values, like in
the example above but they can also be used to add together a variable
and a value, or a variable and another variable:
Example;
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
Unary Operators
 These are operators that act upon a single operand to
produce a new value.
1. unary minus(-)
2. increment(++)
3. decrement(- -)
4. NOT(!)
5. Addressof operator(&)
6. sizeof()
Unary Minus
The minus operator changes the sign of its argument. A positive number
negative, and a negative number becomes positive.
int a = 10;
int b = -a; // b = -10
unary minus is different from the subtraction operator, as subtraction req
operands.
Increment
increment: It is used to increment the value of the variable by 1.
The increment can be done in two ways:
2.1 prefix increment: In this method, the operator precedes the operand (e.g., ++a). The value of
the operand will be altered before it is used.
int a = 1;
int b = ++a; // b = 2
2.2 postfix increment: In this method, the operator follows the operand (e.g., a++). The value
operand will be altered after it is used.
int a = 1;
int b = a++; // b = 1
int c = a; // c = 2
D ECREMENT
3. decrement: It is used to decrement the value of the variable by 1. The decrement can be done in
two ways:
3.1 prefix decrement: In this method, the operator precedes the operand (e.g., – -a). The value of
the operand
will be altered before it is used.
int a = 1; int b = --a; // b = 0
3.2 postfix decrement: In this method, the operator follows the operand (e.g., a- -). The value of
the operand will be altered after it is used.
int a = 1;
int b = a--; // b = 1
int c = a; // c = 0
Not(!)
It is used to reverse the logical state
of its operand. If a condition is true,
then the Logical NOT operator will
make it false.
If X is true, then 1X is false
If X is false, then 1X is true
Addressof Operator
5. Addressof operator(&): It gives an address of a
variable. It is used to return the memory address
of a variable. These addresses returned by the
address-of operator are known as pointers
because they “point” to the variable in memory.
int a;
int *ptr;
ptr = &a; //address of a is copied to location ptr
Sizeof Operator
sizeof(): This operator returns
the size of its operand, in
bytes. The sizeof() operator
always precedes its operand.
Types of Operators
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Bitwise operators
Arithmetic Operators
Operator Name Description Example
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
++ Increment Increases the value of a variable by 1 ++x
-- Decrement Decreases the value of a variable by 1 --x
Assignment Operators
Assignment operators are used to assign values to variables.
In the example below, we use the assignment operator (=) to assign the value 10
to a variable called x:
Example: int x = 10;
The addition assignment operator adds a value to a variable
Example : int x = 10;
x += 5;
List of Assignment Operators
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
Comparison Operator
Comparison operators are used to compare two values.
Note: The return value of a comparison is either true (1) or false (0).
In the following example, we use the greater than operator (>) to
find out if 5 is greater than 3:
int x = 5;
int y = 3;
printf("%d", x > y); // returns 1 (true) because 5 is greater than 3
List of all Comparison operators
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Logical Operators
 Logical operators are used to determine the logic between variables or
values:
Operator Name Description Example
&& Logical and Returns true if both statements are true x < 5 && x < 10
|| Logical or Returns true if one of the statements is true x < 5 || x < 4
! Logical not Reverse the result, returns false if the result
is true
!(x < 5 && x < 10)
Sizeof operator
The memory size (in bytes) of a data type or a variable can be
found with the sizeof operator:
Sizeof Operator
The memory size (in bytes) of a data type or a variable can be found with
the sizeof operator:
int myInt;
float myFloat;
double myDouble;
char myChar;
printf("%lun", sizeof(myInt));
printf("%lun", sizeof(myFloat)); Output: 4 4 8 1
printf("%lun", sizeof(myDouble));
printf("%lun", sizeof(myChar));

More Related Content

PDF
Types of Operators in C programming .pdf
PPTX
C Operators and Control Structures.pptx
PDF
introduction to c programming - Topic 3.pdf
PPTX
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
PPTX
3. C_OperatorsExpressions on c languyage.pptx
PPTX
Operators1.pptx
PDF
Unit ii chapter 1 operator and expressions in c
PDF
Types of Operators in C
Types of Operators in C programming .pdf
C Operators and Control Structures.pptx
introduction to c programming - Topic 3.pdf
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
3. C_OperatorsExpressions on c languyage.pptx
Operators1.pptx
Unit ii chapter 1 operator and expressions in c
Types of Operators in C

Similar to This slide contains information about Operators in C.pptx (20)

PPTX
Simran Roy Operator in Programming in C Language
PPTX
Operator in programming in C engineering
PDF
C Operators and Control Structures.pdf
PPTX
Operators and expressions in C++
PDF
Lecture 3 programming fundaments by abdul rauf.pdf
PPTX
Arithmetic and increment decrement Operator
PPTX
Cse lecture-4.1-c operators and expression
PDF
C++ Expressions Notes
PPTX
presentation of c language. with ternary operator
PPTX
operators.pptx
PPTX
Operators in C programming language.pptx
PPTX
Opreator In "C"
PDF
Chapter 5 - Operators in C++
PPTX
PPTX
OPERATORS OF C++
PPT
Mesics lecture 4 c operators and experssions
PPTX
Operators-computer programming and utilzation
PPTX
C Operators
PPTX
PROGRAMMING IN C - Operators.pptx
PDF
Constructor and destructors
Simran Roy Operator in Programming in C Language
Operator in programming in C engineering
C Operators and Control Structures.pdf
Operators and expressions in C++
Lecture 3 programming fundaments by abdul rauf.pdf
Arithmetic and increment decrement Operator
Cse lecture-4.1-c operators and expression
C++ Expressions Notes
presentation of c language. with ternary operator
operators.pptx
Operators in C programming language.pptx
Opreator In "C"
Chapter 5 - Operators in C++
OPERATORS OF C++
Mesics lecture 4 c operators and experssions
Operators-computer programming and utilzation
C Operators
PROGRAMMING IN C - Operators.pptx
Constructor and destructors
Ad

Recently uploaded (20)

PPT
ALLIED MATHEMATICS -I UNIT III MATRICES.ppt
PPTX
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
PPTX
chapter 3_bem.pptxKLJLKJLKJLKJKJKLJKJKJKHJH
PPT
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
PPTX
Job-opportunities lecture about it skills
PDF
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
PPTX
Prokaryotes v Eukaryotes PowerPoint.pptx
PPT
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
PPTX
1751884730-Visual Basic -Unitj CS B.pptx
PDF
CV of Architect Professor A F M Mohiuddin Akhand.pdf
PPTX
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
PPTX
microtomy kkk. presenting to cryst in gl
PDF
iTop VPN Crack Latest Version 2025 Free Download With Keygen
PPT
2- CELL INJURY L1 Medical (2) gggggggggg
PPTX
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
PDF
Blue-Modern-Elegant-Presentation (1).pdf
PPTX
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
PDF
APNCET2025RESULT Result Result 2025 2025
PPTX
Overview Planner of Soft Skills in a single ppt
PPTX
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
ALLIED MATHEMATICS -I UNIT III MATRICES.ppt
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
chapter 3_bem.pptxKLJLKJLKJLKJKJKLJKJKJKHJH
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
Job-opportunities lecture about it skills
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
Prokaryotes v Eukaryotes PowerPoint.pptx
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
1751884730-Visual Basic -Unitj CS B.pptx
CV of Architect Professor A F M Mohiuddin Akhand.pdf
ESD MODULE-5hdbdhbdbdbdbbdbdbbdndbdbdbdbbdbd
microtomy kkk. presenting to cryst in gl
iTop VPN Crack Latest Version 2025 Free Download With Keygen
2- CELL INJURY L1 Medical (2) gggggggggg
OnePlus 13R – ⚡ All-Rounder King Performance: Snapdragon 8 Gen 3 – same as iQ...
Blue-Modern-Elegant-Presentation (1).pdf
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
APNCET2025RESULT Result Result 2025 2025
Overview Planner of Soft Skills in a single ppt
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
Ad

This slide contains information about Operators in C.pptx

  • 1. Operators PRESENTED BY : MR. MADHUR THAPLIYAL ASSISTANT PROFESSOR SCHOOL OF COMPUTING DEPARTMENT OF COMPUTER APPLICATIONS
  • 2. Definition  Operators in c are used to perform operations on variables and values. In example below we used + operator to add together two values: int myNum = 100+50; Although the + operator is also used to add together two values, like in the example above but they can also be used to add together a variable and a value, or a variable and another variable: Example; int sum1 = 100 + 50; // 150 (100 + 50) int sum2 = sum1 + 250; // 400 (150 + 250) int sum3 = sum2 + sum2; // 800 (400 + 400)
  • 3. Unary Operators  These are operators that act upon a single operand to produce a new value. 1. unary minus(-) 2. increment(++) 3. decrement(- -) 4. NOT(!) 5. Addressof operator(&) 6. sizeof()
  • 4. Unary Minus The minus operator changes the sign of its argument. A positive number negative, and a negative number becomes positive. int a = 10; int b = -a; // b = -10 unary minus is different from the subtraction operator, as subtraction req operands.
  • 5. Increment increment: It is used to increment the value of the variable by 1. The increment can be done in two ways: 2.1 prefix increment: In this method, the operator precedes the operand (e.g., ++a). The value of the operand will be altered before it is used. int a = 1; int b = ++a; // b = 2 2.2 postfix increment: In this method, the operator follows the operand (e.g., a++). The value operand will be altered after it is used. int a = 1; int b = a++; // b = 1 int c = a; // c = 2
  • 6. D ECREMENT 3. decrement: It is used to decrement the value of the variable by 1. The decrement can be done in two ways: 3.1 prefix decrement: In this method, the operator precedes the operand (e.g., – -a). The value of the operand will be altered before it is used. int a = 1; int b = --a; // b = 0 3.2 postfix decrement: In this method, the operator follows the operand (e.g., a- -). The value of the operand will be altered after it is used. int a = 1; int b = a--; // b = 1 int c = a; // c = 0
  • 7. Not(!) It is used to reverse the logical state of its operand. If a condition is true, then the Logical NOT operator will make it false. If X is true, then 1X is false If X is false, then 1X is true
  • 8. Addressof Operator 5. Addressof operator(&): It gives an address of a variable. It is used to return the memory address of a variable. These addresses returned by the address-of operator are known as pointers because they “point” to the variable in memory. int a; int *ptr; ptr = &a; //address of a is copied to location ptr
  • 9. Sizeof Operator sizeof(): This operator returns the size of its operand, in bytes. The sizeof() operator always precedes its operand.
  • 10. Types of Operators • Arithmetic operators • Assignment operators • Comparison operators • Logical operators • Bitwise operators
  • 11. Arithmetic Operators Operator Name Description Example + Addition Adds together two values x + y - Subtraction Subtracts one value from another x - y * Multiplication Multiplies two values x * y / Division Divides one value by another x / y % Modulus Returns the division remainder x % y ++ Increment Increases the value of a variable by 1 ++x -- Decrement Decreases the value of a variable by 1 --x
  • 12. Assignment Operators Assignment operators are used to assign values to variables. In the example below, we use the assignment operator (=) to assign the value 10 to a variable called x: Example: int x = 10; The addition assignment operator adds a value to a variable Example : int x = 10; x += 5;
  • 13. List of Assignment Operators Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 &= x &= 3 x = x & 3 |= x |= 3 x = x | 3 ^= x ^= 3 x = x ^ 3 >>= x >>= 3 x = x >> 3 <<= x <<= 3 x = x << 3
  • 14. Comparison Operator Comparison operators are used to compare two values. Note: The return value of a comparison is either true (1) or false (0). In the following example, we use the greater than operator (>) to find out if 5 is greater than 3: int x = 5; int y = 3; printf("%d", x > y); // returns 1 (true) because 5 is greater than 3
  • 15. List of all Comparison operators Operator Name Example == Equal to x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 16. Logical Operators  Logical operators are used to determine the logic between variables or values: Operator Name Description Example && Logical and Returns true if both statements are true x < 5 && x < 10 || Logical or Returns true if one of the statements is true x < 5 || x < 4 ! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10)
  • 17. Sizeof operator The memory size (in bytes) of a data type or a variable can be found with the sizeof operator:
  • 18. Sizeof Operator The memory size (in bytes) of a data type or a variable can be found with the sizeof operator: int myInt; float myFloat; double myDouble; char myChar; printf("%lun", sizeof(myInt)); printf("%lun", sizeof(myFloat)); Output: 4 4 8 1 printf("%lun", sizeof(myDouble)); printf("%lun", sizeof(myChar));