SlideShare a Scribd company logo
Operators
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Misc Operators
Arithmetic Operators
Assume variable Aholds 10 and variable B holds 20 then:
Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiplies both operands A * B will give 200
/ Divides numerator by de-numerator B / A will give 2
% Modulus Operator and remainder of after an
integer division
B % A will give 0
++ Increments operator increases integer value
by one
A++ will give 11
-- Decrements operator decreases integer
value by one
A-- will give 9
#include <stdio.h>
void main()
{
int a=20;
int b=10;
printf("Answer %d+%d=%d n",a,b,a+b);
printf("Answer %d-%d=%d n",a,b,a-b);
printf("Answer %d*%d=%d n",a,b,a*b);
printf("Answer %d/%d=%d n",a,b,a/b);
printf("Answer %d MODULAS %d=%d n",a,b,a%b);
printf("Answer a++=%d n",a,a++);
printf("Answer a--=%d n",a,a--);
}
Answer 20+10=30
Answer 20-10=10
Answer 20*10=200
Answer 20/10=2
Answer 20 MODULAS 10=0
Answer a++=21
Answer a--=20
Press any key to continue . . .
output
Relational Operators
Assume variable Aholds 10 and variable B holds 20, then:
Operator Description Example
== Checks if the values of two operands are equal or
not, if yes then condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are 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>
void main()
{
int a=20;
int b=10;
int c;
c=(a==b);
c=(a!=b);
c=(a<b);
c=(a>b);
c=(a<=b);
c=(a<=b);
printf("Answer %d==%d= %d n",a,b,c);
printf("Answer %d!=%d= %d n",a,b,c);
printf("Answer %d<%d= %d n",a,b,c);
printf("Answer %d>%d= %d n",a,b,c);
printf("Answer %d<=%d= %d n",a,b,c);
printf("Answer %d>=%d= %d n",a,b,c);
}
Answer 20==10= 0
Answer 20!=10= 0
Answer 20<10= 0
Answer 20>10= 0
Answer 20<=10= 0
Answer 20>=10= 0
Press any key to continue . . .
OUTPUT
#include <stdio.h>
void main()
{
int a=20;
int b=10;
int c;
c=(a==b);
printf("Answer %d==%d= %d n",a,b,c);
c=(a!=b);
printf("Answer %d!=%d= %d n",a,b,c);
c=(a<b);
printf("Answer %d<%d= %d n",a,b,c);
c=(a>b);
printf("Answer %d>%d= %d n",a,b,c);
c=(a<=b);
printf("Answer %d<=%d= %d n",a,b,c);
c=(a<=b);
printf("Answer %d>=%d= %d n",a,b,c);
}
Answer 20==10= 0
Answer 20!=10= 1
Answer 20<10= 0
Answer 20>10= 1
Answer 20<=10= 0
Answer 20>=10= 0
Press any key to continue
. . .
OUTPUT
#include <stdio.h>
void main()
{
int a=20;
int b=10;
printf("Answer %d==%d= %d n",a,b,a==b);
printf("Answer %d!=%d= %d n",a,b,a!=b);
printf("Answer %d<%d= %d n",a,b,a<b);
printf("Answer %d>%d= %d n",a,b,a>b);
printf("Answer %d<=%d= %d n",a,b,a<=b);
printf("Answer %d>=%d= %d n",a,b,a<=b);
}
Answer 20==10= 0
Answer 20!=10= 1
Answer 20<10= 0
Answer 20>10= 1
Answer 20<=10= 0
Answer 20>=10= 0
Press any key to continue . . .
Logical Operators
Assume variable A holds 1 and variable B holds 0, then:
Operator Description Example
&& Called Logical AND operator. If both the
operands are non-zero, then condition
becomes true.
(A && B) is false.
|| Called Logical OR Operator. If any of the
two operands is non-zero, then condition
becomes true
(A || B) is true.
! Called Logical NOT Operator. Use to
reverses the logical state of its operand. If
a condition is true then Logical NOT
operator will make false.
!(A && B) is true.
// LOGICAL AND
#include <stdio.h>
void main()
{
printf("______________n");
printf("| A B C |n");
printf("______________n");
printf("| 0 0 %d |n",0&&0);
printf("| 0 1 %d |n",0&&1);
printf("| 1 0 %d |n",1&&0);
printf("| 1 1 %d |n",1&&1);
printf("______________n");
}
______________
| A B C |
______________
| 0 0 0 |
| 0 1 0 |
| 1 0 0 |
| 1 1 1 |
______________
Press any key to continue . . .
OUTPUT
// LOGICAL OR
#include <stdio.h>
void main()
{
printf("______________n");
printf("| A B C |n");
printf("______________n");
printf("| 0 0 %d |n",0||0);
printf("| 0 1 %d |n",0||1);
printf("| 1 0 %d |n",1||0);
printf("| 1 1 %d |n",1||1);
printf("______________n");
}
______________
| A B C |
______________
| 0 0 0 |
| 0 1 1 |
| 1 0 1 |
| 1 1 1 |
______________
Press any key to continue . . .
OUTPUT
// LOGICAL NOT GATE
#include <stdio.h>
void main()
{
int a=0;
int b=1;
printf("__________________________n");
printf("| A(input) C(output) |n");
printf("|________________________|n");
printf("| 0 %d |n",!a);
printf("| 1 %d |n",!b);
printf("|________________________|n");
}
OUTPUT
__________________________
| A(input) C(output) |
|________________________|
| 0 1 |
| 1 0 |
|________________________|
Press any key to continue . . .
// LOGICAL NOT+OR=NOR
#include <stdio.h>
void main()
{
printf("______________n");
printf("| A B C |n");
printf("______________n");
printf("| 0 0 %d |n",!(0||0));
printf("| 0 1 %d |n",!(0||1));
printf("| 1 0 %d |n",!(1||0));
printf("| 1 1 %d |n",!(1||1));
printf("______________n");
}
______________
| A B C |
______________
| 0 0 1 |
| 0 1 0 |
| 1 0 0 |
| 1 1 0 |
______________
Press any key to continue . . .
// LOGICAL NOT+AND=NAND
#include <stdio.h>
void main()
{
printf("______________n");
printf("| A B C |n");
printf("______________n");
printf("| 0 0 %d |n",!(0&&0));
printf("| 0 1 %d |n",!(0&&1));
printf("| 1 0 %d |n",!(1&&0));
printf("| 1 1 %d |n",!(1&&1));
printf("______________n");
}
______________
| A B C |
______________
| 0 0 1 |
| 0 1 1 |
| 1 0 1 |
| 1 1 0 |
______________
Press any key to continue . . .
OUTPUT
Operator Description Example
& Binary AND Operator copies a bit to the result if it
exists in both operands.
(A & B) will give 12, which is
0000 1100
| Binary OR Operator copies a bit if it exists in either
operand.
(A | B) will give 61, which is
0011 1101
^ Binary XOR Operator copies the bit if it is set in
one operand but not both.
(A ^ B) will give 49, which is
0011 0001
~ Binary Ones Complement Operator is unary and
has the effect of 'flipping' bits.
(~A ) will give -61, which is
1100 0011 in 2's complement
form.
<< Binary Left Shift Operator. The left operands value
is moved left by the number of bits specified by
the right operand.
A << 2 will give 240 which is
1111 0000
>> Binary Right Shift Operator. The left operands
value is moved right by the number of bits
specified by the right operand.
A >> 2 will give 15 which is
0000 1111
Bitwise Operators
// BITWISE AND
#include <stdio.h>
void main()
{
int a=0;
int b=1;
printf("__________________________n");
printf("| A B C(output) |n");
printf("|________________________|n");
printf("| 0 0 %d |n",0&0);
printf("| 0 1 %d |n",0&1);
printf("| 1 0 %d |n",1&0);
printf("| 1 1 %d |n",1&1);
printf("|________________________|n");
}
__________________________
| A B C(output) |
|________________________|
| 0 0 0 |
| 0 1 0 |
| 1 0 0 |
| 1 1 1 |
|________________________|
Press any key to continue . . .
// BINARY OR
#include <stdio.h>
void main()
{
int a=0;
int b=1;
printf("__________________________n");
printf("| A B C(output) |n");
printf("|________________________|n");
printf("| 0 0 %d |n",0|0);
printf("| 0 1 %d |n",0|1);
printf("| 1 0 %d |n",1|0);
printf("| 1 1 %d |n",1|1);
printf("|________________________|n");
}
__________________________
| A B C(output) |
|________________________|
| 0 0 0 |
| 0 1 1 |
| 1 0 1 |
| 1 1 1 |
|________________________|
Press any key to continue . . .
// BINARY XOR
#include <stdio.h>
void main()
{
int a=0;
int b=1;
printf("__________________________n");
printf("| A B C(output) |n");
printf("|________________________|n");
printf("| 0 0 %d |n",0^0);
printf("| 0 1 %d |n",0^1);
printf("| 1 0 %d |n",1^0);
printf("| 1 1 %d |n",1^1);
printf("|________________________|n");
}
__________________________
| A B C(output) |
|________________________|
| 0 0 0 |
| 0 1 1 |
| 1 0 1 |
| 1 1 0 |
|________________________|
Press any key to continue . . .
// BINARY COMPLEMNT
#include <stdio.h>
void main()
{
int a=0;
int b=1;
printf("__________________________n");
printf("| A B C(output) |n");
printf("|________________________|n");
printf("| 0 0 %d |n",~(60));
printf("|________________________|n");
}
__________________________
| A B C(output) |
|________________________|
| 0 0 -61 |
|________________________|
Press any key to continue . . .
Bitwise operator works on bits and perform bit-by-bit operation.
The truth tables for &, |, and ^ are as follows:
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume if A = 60; and B = 13; now in binary format they will be as
follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Assignment Operators
Operator Description Example
= Simple assignment operator, Assigns values from right side operands to
left side operand
C = A + B will assign value of A + B into
C
+= Add AND assignment operator, It adds right operand to the left operand
and assign the result to left operand
C += A is equivalent to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the
left operand and assign the result to left operand
C -= A is equivalent to C = C - A
*= Multiply AND assignment operator, It multiplies right operand with the
left operand and assign the result to left operand
C *= A is equivalent to C = C * A
/= Divide AND assignment operator, It divides left operand with the right
operand and assign the result to left operand
C /= A is equivalent to C = C / A
%= Modulus AND assignment operator, It takes modulus using two
operands and assign the result to left operand
C %= A is equivalent to C = C % A
<<= Left shift AND assignment operator C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator C &= 2 is same as C = C & 2
^= bitwise exclusive OR and assignment operator C ^= 2 is same as C = C ^ 2
|= bitwise inclusive OR and assignment operator C |= 2 is same as C = C | 2
Misc Operators ↦ sizeof & ternary
Operator Description Example
sizeof() Returns the size of an variable. sizeof(a), where a is
integer, will return 4.
& Returns the address of an variable. &a; will give actual
address of the variable.
* Pointer to a variable. *a; will pointer to a
variable.
? : Conditional Expression If Condition is true ? Then
value X : Otherwise value
Y

More Related Content

What's hot (19)

Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
Function basics
Function basicsFunction basics
Function basics
mohamed sikander
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
Rumman Ansari
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
week-10x
week-10xweek-10x
week-10x
KITE www.kitecolleges.com
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
week-18x
week-18xweek-18x
week-18x
KITE www.kitecolleges.com
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
week-6x
week-6xweek-6x
week-6x
KITE www.kitecolleges.com
 
Cpl
CplCpl
Cpl
Ayesha Shariff
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
week-1x
week-1xweek-1x
week-1x
KITE www.kitecolleges.com
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
Rumman Ansari
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 

Viewers also liked (19)

C Programming Language Part 5
C Programming Language Part 5C Programming Language Part 5
C Programming Language Part 5
Rumman Ansari
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
Rumman Ansari
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
Rumman Ansari
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
Rumman Ansari
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 
Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4
Marcos Baldovi
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
C programming basics
C  programming basicsC  programming basics
C programming basics
argusacademy
 
у рідному краї серце співає
у рідному краї серце співаєу рідному краї серце співає
у рідному краї серце співає
Poltava municipal lyceum #1
 
Eric Stewart Resume
Eric Stewart ResumeEric Stewart Resume
Eric Stewart Resume
Eric Stewart
 
media slide
media slidemedia slide
media slide
claudiafenogliog123
 
реквієм за убієнних голодом
реквієм за убієнних голодомреквієм за убієнних голодом
реквієм за убієнних голодом
Poltava municipal lyceum #1
 
Work Life Leader Manifesto
Work Life Leader Manifesto Work Life Leader Manifesto
Work Life Leader Manifesto
Julie Cohen
 
20141203 第5回社内勉強会(佐藤)
20141203 第5回社内勉強会(佐藤)20141203 第5回社内勉強会(佐藤)
20141203 第5回社内勉強会(佐藤)
ksatoo
 
відповідаючи перед майбутнім
відповідаючи перед майбутнімвідповідаючи перед майбутнім
відповідаючи перед майбутнім
Poltava municipal lyceum #1
 
ME461 Final Presentation
ME461 Final PresentationME461 Final Presentation
ME461 Final Presentation
Shireen Kheradpey
 
Ashida Project Division
Ashida Project DivisionAshida Project Division
Ashida Project Division
SWAPNIL GHAISAS
 
C Programming Language Part 5
C Programming Language Part 5C Programming Language Part 5
C Programming Language Part 5
Rumman Ansari
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
Rumman Ansari
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
Rumman Ansari
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
Rumman Ansari
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 
Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4
Marcos Baldovi
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
C programming basics
C  programming basicsC  programming basics
C programming basics
argusacademy
 
у рідному краї серце співає
у рідному краї серце співаєу рідному краї серце співає
у рідному краї серце співає
Poltava municipal lyceum #1
 
Eric Stewart Resume
Eric Stewart ResumeEric Stewart Resume
Eric Stewart Resume
Eric Stewart
 
реквієм за убієнних голодом
реквієм за убієнних голодомреквієм за убієнних голодом
реквієм за убієнних голодом
Poltava municipal lyceum #1
 
Work Life Leader Manifesto
Work Life Leader Manifesto Work Life Leader Manifesto
Work Life Leader Manifesto
Julie Cohen
 
20141203 第5回社内勉強会(佐藤)
20141203 第5回社内勉強会(佐藤)20141203 第5回社内勉強会(佐藤)
20141203 第5回社内勉強会(佐藤)
ksatoo
 
відповідаючи перед майбутнім
відповідаючи перед майбутнімвідповідаючи перед майбутнім
відповідаючи перед майбутнім
Poltava municipal lyceum #1
 
Ad

Similar to C Programming Language Part 4 (20)

C operators
C operators C operators
C operators
AbiramiT9
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
ramanathan2006
 
Theory3
Theory3Theory3
Theory3
Dr.M.Karthika parthasarathy
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
Hemantha Kulathilake
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
Chukka Nikhil Chakravarthy
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
Nithya K
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
MaryJacob24
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
Hassaan Rahman
 
C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh
AnkitSinghRajput35
 
Operators
OperatorsOperators
Operators
VijayaLakshmi506
 
C programming Assignments and Questions.pdf
C programming Assignments and  Questions.pdfC programming Assignments and  Questions.pdf
C programming Assignments and Questions.pdf
rajd20284
 
C operators
C operatorsC operators
C operators
Rupanshi rawat
 
Programming C Part 02
Programming C Part 02Programming C Part 02
Programming C Part 02
Raselmondalmehedi
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
S.M. Salaquzzaman
 
Operators in C programming language.pptx
Operators in C programming language.pptxOperators in C programming language.pptx
Operators in C programming language.pptx
b221382
 
btwggggggggggggggggggggggggggggggisop correct (1).pptx
btwggggggggggggggggggggggggggggggisop correct (1).pptxbtwggggggggggggggggggggggggggggggisop correct (1).pptx
btwggggggggggggggggggggggggggggggisop correct (1).pptx
Orin18
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Sreedhar Chowdam
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
C operators
C operators C operators
C operators
AbiramiT9
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
ramanathan2006
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
Nithya K
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
MaryJacob24
 
C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh
AnkitSinghRajput35
 
C programming Assignments and Questions.pdf
C programming Assignments and  Questions.pdfC programming Assignments and  Questions.pdf
C programming Assignments and Questions.pdf
rajd20284
 
Operators in C programming language.pptx
Operators in C programming language.pptxOperators in C programming language.pptx
Operators in C programming language.pptx
b221382
 
btwggggggggggggggggggggggggggggggisop correct (1).pptx
btwggggggggggggggggggggggggggggggisop correct (1).pptxbtwggggggggggggggggggggggggggggggisop correct (1).pptx
btwggggggggggggggggggggggggggggggisop correct (1).pptx
Orin18
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Sreedhar Chowdam
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
Ad

More from Rumman Ansari (19)

Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
C programming exercises and solutions
C programming exercises and solutions C programming exercises and solutions
C programming exercises and solutions
Rumman Ansari
 
Java Tutorial best website
Java Tutorial best websiteJava Tutorial best website
Java Tutorial best website
Rumman Ansari
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
servlet programming
servlet programmingservlet programming
servlet programming
Rumman Ansari
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
What is token c programming
What is token c programmingWhat is token c programming
What is token c programming
Rumman Ansari
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
Rumman Ansari
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
Rumman Ansari
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
Rumman Ansari
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2
Rumman Ansari
 
C Programming
C ProgrammingC Programming
C Programming
Rumman Ansari
 
Tail recursion
Tail recursionTail recursion
Tail recursion
Rumman Ansari
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 
Spyware manual
Spyware  manualSpyware  manual
Spyware manual
Rumman Ansari
 
Linked list
Linked listLinked list
Linked list
Rumman Ansari
 
C programming exercises and solutions
C programming exercises and solutions C programming exercises and solutions
C programming exercises and solutions
Rumman Ansari
 
Java Tutorial best website
Java Tutorial best websiteJava Tutorial best website
Java Tutorial best website
Rumman Ansari
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
What is token c programming
What is token c programmingWhat is token c programming
What is token c programming
Rumman Ansari
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
Rumman Ansari
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
Rumman Ansari
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
Rumman Ansari
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2
Rumman Ansari
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 

Recently uploaded (20)

ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdfISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
ISO 5011 Air Filter Catalogues .pdf
ISO 5011 Air Filter Catalogues      .pdfISO 5011 Air Filter Catalogues      .pdf
ISO 5011 Air Filter Catalogues .pdf
FILTRATION ENGINEERING & CUNSULTANT
 
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCHUNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
Sridhar191373
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdfISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCHUNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
Sridhar191373
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 

C Programming Language Part 4

  • 1. Operators 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Bitwise Operators 5. Assignment Operators 6. Misc Operators
  • 2. Arithmetic Operators Assume variable Aholds 10 and variable B holds 20 then: Operator Description Example + Adds two operands A + B will give 30 - Subtracts second operand from the first A - B will give -10 * Multiplies both operands A * B will give 200 / Divides numerator by de-numerator B / A will give 2 % Modulus Operator and remainder of after an integer division B % A will give 0 ++ Increments operator increases integer value by one A++ will give 11 -- Decrements operator decreases integer value by one A-- will give 9
  • 3. #include <stdio.h> void main() { int a=20; int b=10; printf("Answer %d+%d=%d n",a,b,a+b); printf("Answer %d-%d=%d n",a,b,a-b); printf("Answer %d*%d=%d n",a,b,a*b); printf("Answer %d/%d=%d n",a,b,a/b); printf("Answer %d MODULAS %d=%d n",a,b,a%b); printf("Answer a++=%d n",a,a++); printf("Answer a--=%d n",a,a--); } Answer 20+10=30 Answer 20-10=10 Answer 20*10=200 Answer 20/10=2 Answer 20 MODULAS 10=0 Answer a++=21 Answer a--=20 Press any key to continue . . . output
  • 4. Relational Operators Assume variable Aholds 10 and variable B holds 20, then: Operator Description Example == Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the values of two operands are 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.
  • 5. #include <stdio.h> void main() { int a=20; int b=10; int c; c=(a==b); c=(a!=b); c=(a<b); c=(a>b); c=(a<=b); c=(a<=b); printf("Answer %d==%d= %d n",a,b,c); printf("Answer %d!=%d= %d n",a,b,c); printf("Answer %d<%d= %d n",a,b,c); printf("Answer %d>%d= %d n",a,b,c); printf("Answer %d<=%d= %d n",a,b,c); printf("Answer %d>=%d= %d n",a,b,c); } Answer 20==10= 0 Answer 20!=10= 0 Answer 20<10= 0 Answer 20>10= 0 Answer 20<=10= 0 Answer 20>=10= 0 Press any key to continue . . . OUTPUT
  • 6. #include <stdio.h> void main() { int a=20; int b=10; int c; c=(a==b); printf("Answer %d==%d= %d n",a,b,c); c=(a!=b); printf("Answer %d!=%d= %d n",a,b,c); c=(a<b); printf("Answer %d<%d= %d n",a,b,c); c=(a>b); printf("Answer %d>%d= %d n",a,b,c); c=(a<=b); printf("Answer %d<=%d= %d n",a,b,c); c=(a<=b); printf("Answer %d>=%d= %d n",a,b,c); } Answer 20==10= 0 Answer 20!=10= 1 Answer 20<10= 0 Answer 20>10= 1 Answer 20<=10= 0 Answer 20>=10= 0 Press any key to continue . . . OUTPUT
  • 7. #include <stdio.h> void main() { int a=20; int b=10; printf("Answer %d==%d= %d n",a,b,a==b); printf("Answer %d!=%d= %d n",a,b,a!=b); printf("Answer %d<%d= %d n",a,b,a<b); printf("Answer %d>%d= %d n",a,b,a>b); printf("Answer %d<=%d= %d n",a,b,a<=b); printf("Answer %d>=%d= %d n",a,b,a<=b); } Answer 20==10= 0 Answer 20!=10= 1 Answer 20<10= 0 Answer 20>10= 1 Answer 20<=10= 0 Answer 20>=10= 0 Press any key to continue . . .
  • 8. Logical Operators Assume variable A holds 1 and variable B holds 0, then: Operator Description Example && Called Logical AND operator. If both the operands are non-zero, then condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true (A || B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. !(A && B) is true.
  • 9. // LOGICAL AND #include <stdio.h> void main() { printf("______________n"); printf("| A B C |n"); printf("______________n"); printf("| 0 0 %d |n",0&&0); printf("| 0 1 %d |n",0&&1); printf("| 1 0 %d |n",1&&0); printf("| 1 1 %d |n",1&&1); printf("______________n"); } ______________ | A B C | ______________ | 0 0 0 | | 0 1 0 | | 1 0 0 | | 1 1 1 | ______________ Press any key to continue . . . OUTPUT
  • 10. // LOGICAL OR #include <stdio.h> void main() { printf("______________n"); printf("| A B C |n"); printf("______________n"); printf("| 0 0 %d |n",0||0); printf("| 0 1 %d |n",0||1); printf("| 1 0 %d |n",1||0); printf("| 1 1 %d |n",1||1); printf("______________n"); } ______________ | A B C | ______________ | 0 0 0 | | 0 1 1 | | 1 0 1 | | 1 1 1 | ______________ Press any key to continue . . . OUTPUT
  • 11. // LOGICAL NOT GATE #include <stdio.h> void main() { int a=0; int b=1; printf("__________________________n"); printf("| A(input) C(output) |n"); printf("|________________________|n"); printf("| 0 %d |n",!a); printf("| 1 %d |n",!b); printf("|________________________|n"); } OUTPUT __________________________ | A(input) C(output) | |________________________| | 0 1 | | 1 0 | |________________________| Press any key to continue . . .
  • 12. // LOGICAL NOT+OR=NOR #include <stdio.h> void main() { printf("______________n"); printf("| A B C |n"); printf("______________n"); printf("| 0 0 %d |n",!(0||0)); printf("| 0 1 %d |n",!(0||1)); printf("| 1 0 %d |n",!(1||0)); printf("| 1 1 %d |n",!(1||1)); printf("______________n"); } ______________ | A B C | ______________ | 0 0 1 | | 0 1 0 | | 1 0 0 | | 1 1 0 | ______________ Press any key to continue . . .
  • 13. // LOGICAL NOT+AND=NAND #include <stdio.h> void main() { printf("______________n"); printf("| A B C |n"); printf("______________n"); printf("| 0 0 %d |n",!(0&&0)); printf("| 0 1 %d |n",!(0&&1)); printf("| 1 0 %d |n",!(1&&0)); printf("| 1 1 %d |n",!(1&&1)); printf("______________n"); } ______________ | A B C | ______________ | 0 0 1 | | 0 1 1 | | 1 0 1 | | 1 1 0 | ______________ Press any key to continue . . . OUTPUT
  • 14. Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12, which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61, which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49, which is 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61, which is 1100 0011 in 2's complement form. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15 which is 0000 1111 Bitwise Operators
  • 15. // BITWISE AND #include <stdio.h> void main() { int a=0; int b=1; printf("__________________________n"); printf("| A B C(output) |n"); printf("|________________________|n"); printf("| 0 0 %d |n",0&0); printf("| 0 1 %d |n",0&1); printf("| 1 0 %d |n",1&0); printf("| 1 1 %d |n",1&1); printf("|________________________|n"); } __________________________ | A B C(output) | |________________________| | 0 0 0 | | 0 1 0 | | 1 0 0 | | 1 1 1 | |________________________| Press any key to continue . . .
  • 16. // BINARY OR #include <stdio.h> void main() { int a=0; int b=1; printf("__________________________n"); printf("| A B C(output) |n"); printf("|________________________|n"); printf("| 0 0 %d |n",0|0); printf("| 0 1 %d |n",0|1); printf("| 1 0 %d |n",1|0); printf("| 1 1 %d |n",1|1); printf("|________________________|n"); } __________________________ | A B C(output) | |________________________| | 0 0 0 | | 0 1 1 | | 1 0 1 | | 1 1 1 | |________________________| Press any key to continue . . .
  • 17. // BINARY XOR #include <stdio.h> void main() { int a=0; int b=1; printf("__________________________n"); printf("| A B C(output) |n"); printf("|________________________|n"); printf("| 0 0 %d |n",0^0); printf("| 0 1 %d |n",0^1); printf("| 1 0 %d |n",1^0); printf("| 1 1 %d |n",1^1); printf("|________________________|n"); } __________________________ | A B C(output) | |________________________| | 0 0 0 | | 0 1 1 | | 1 0 1 | | 1 1 0 | |________________________| Press any key to continue . . .
  • 18. // BINARY COMPLEMNT #include <stdio.h> void main() { int a=0; int b=1; printf("__________________________n"); printf("| A B C(output) |n"); printf("|________________________|n"); printf("| 0 0 %d |n",~(60)); printf("|________________________|n"); } __________________________ | A B C(output) | |________________________| | 0 0 -61 | |________________________| Press any key to continue . . .
  • 19. Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows: p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 20. Assume if A = 60; and B = 13; now in binary format they will be as follows: A = 0011 1100 B = 0000 1101 ----------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011
  • 21. Assignment Operators Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A <<= Left shift AND assignment operator C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2 &= Bitwise AND assignment operator C &= 2 is same as C = C & 2 ^= bitwise exclusive OR and assignment operator C ^= 2 is same as C = C ^ 2 |= bitwise inclusive OR and assignment operator C |= 2 is same as C = C | 2
  • 22. Misc Operators ↦ sizeof & ternary Operator Description Example sizeof() Returns the size of an variable. sizeof(a), where a is integer, will return 4. & Returns the address of an variable. &a; will give actual address of the variable. * Pointer to a variable. *a; will pointer to a variable. ? : Conditional Expression If Condition is true ? Then value X : Otherwise value Y