Operators in C Programming

OPERATORS
N.V.RAJA SEKHAR REDDY
C Programming Tutorials
www.programming9.com
What is an operator?
 An operator is a symbol that tells the
computer to perform certain mathematical
or logical manipulations.
 These operators are used in programs to
manipulate data and variables.
2 www.programming9.com
Types of Operators
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement
operators
6. Conditional operators
7. Bitwise operators
8. Special operators3 www.programming9.com
ARITHMETIC OPERATORS:
 Arithmetic operators are used to perform numerical
calculations among the values.
OPERATOR MEANING
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
4 www.programming9.com
#include<stdio.h>
int main()
{
int a, b, add, sub, mul, div, rem;
printf("Enter a, b values : ");
scanf("%d%d",&a,&b); // Reading two values
add=a+b; // Addition Operator
sub=a-b; // Subtraction Operator
mul=a*b; // Multiplication Operator
div=a/b; // Division Operator
rem=a%b; // Remainder (Modulo) Operator
printf("Result of addition is=%dn", add);
printf("Result of subtraction=%dn", sub);
printf("Result of multiplication is=%dn", mul);
printf("Result of division is=%dn", div);
printf("Result of remainder=%dn",rem);
return 0; }
5 www.programming9.com
RELATIONAL OPERATOR:
 Relational Operators are used to compare two
quantities and take certain decision depending on
their relation.
If the specified relation is true it returns one.
If the specified relation is false it returns zero.
OPERATOR MEANING
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Is equal to
!= Is not equal to
6 www.programming9.com
#include<stdio.h>
void main()
{
int a, b;
printf(“Enter values for a and b : ");
scanf("%d %d", &a, &b);
printf("n The < value of a is %d", a<b);
printf("n The <= value of a is %d", a<=b);
printf("n The > value of a is %d", a>b);
printf("n The >= value of a is %d", a>=b);
printf("n The == value of a is %d", a==b);
printf("n The != value of a is %d", a!=b);
}
7 www.programming9.com
Example Program
LOGICAL OPERATORS:
 These operators are used for testing more than one
condition and making decisions.
'c' has three logical operators they are:
OPERATOR MEANING
&& Logical AND
|| Logical OR
! Logical NOT
8 www.programming9.com
Logical Operators Example Program
#include<stdio.h>
void main()
{
int a, b;
printf(“Enter values for a and b : ");
scanf(“%d %d", &a, &b);
printf("n %d",(a<b)&&(a!=b));
printf("n %d",(a<b)||(b<a));
printf("n %d",!(a==b));
}
9 www.programming9.com
ASSIGNMENT OPERATORS
 These operators are used for assigning the result of
an expression to a variable.
 b=a;
OPERATORS:
==, +=, -=, *=, /=, %=,
>>=, <<=, &=, |=, ^=
10 www.programming9.com
Assignment Operators Example
#include<stdio.h>
void main()
{
int a, b, c;
printf("Enter the values for a and b : ");
scanf("%d %d",&a,&b);
printf("n the values of= is:%d",c=a+b);
printf("n the values of +=is:%d",c+=b);
printf("n the value of-= is:%d",c-=a);
printf("n the value of *=is:%d",c*=a);
printf("n the value of /=is:%d",c/=b);
printf("n the value of %=is:%d",c%=b);
}
11 www.programming9.com
INCREMENT & DECREMENT
OPERATORS
Two most useful operators which are present in 'c'
are increment and decrement operators.
Operators: ++ and --
The operator ++ adds one to the operand
The operator -- subtracts one from the operand.
Both are unary operators and can be used as pre or
post increment/decrement.
12 www.programming9.com
INCREMENT & DECREMENT OPERATORS
EXAMPLE
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the values for a and b :");
scanf("%d %d", &a, &b);
printf("n The value of c is %d", c=++a);
printf("n The value of c is %d", c=a++);
printf("n The value of c is %d", c=--b);
printf("n The value of c is %d", c=b--);
}
13 www.programming9.com
CONDITIONAL OPERATORS
These conditional operator are used to construct
conditional expressions of the form.
Syntax:
exp1?exp2:exp3.
where exp1,exp2,exp3 are expressions.
Operator: ?: (ternary operator)
14 www.programming9.com
Conditional Operators Example
#include<stdio.h>
void main()
{
int a, b, x;
printf("Enter the values of a add b : ");
scanf("%d %d", &a, &b);
x=(a>b)?a:b;
printf("Biggest Value is :%d",x);
}
15 www.programming9.com
BITWISE OPERATORS
 These operators works on bit level
 Applied to Integers only
OPERATOR MEANING
& Bitwise AND
| Bitwise OR
^ Bitwise Exclusive OR
<< Shift Left
>> Shift Right
16 www.programming9.com
SPECIAL OPERATORS
'C' supports some special operators such as
comma operator, sizeof operator and pointer
operators.
Comma operator:
the comma operator is used to combine
related expressions.
A comma linked list of expressions are
evaluated left to right and the value of right most
expression is the value of combined
expression..
Example: value=(x=10, y=5, x+y);
17 www.programming9.com
Special Operators Contd…
Sizeof Operator:
Sizeof is an operator used to return the number
of bytes the operand occupies.
Syntax:
m=sizeof(sum);
k=sizeof(2351);
18 www.programming9.com
www.programming9.com
Like us @
www.facebook.com/programming9
19 www.programming9.com
1 de 19

Recomendados

Data types in CData types in C
Data types in CTarun Sharma
33.6K visualizações12 slides
C language pptC language ppt
C language pptĞäùråv Júñêjå
193.4K visualizações26 slides
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
10.3K visualizações20 slides
Data typesData types
Data typesZahid Hussain
29.4K visualizações20 slides
C tokensC tokens
C tokensManu1325
20.8K visualizações10 slides
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
164.7K visualizações39 slides

Mais conteúdo relacionado

Mais procurados

Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
6.2K visualizações11 slides
Pointer in cPointer in c
Pointer in clavanya marichamy
15K visualizações14 slides
Functions in CFunctions in C
Functions in CKamal Acharya
25.1K visualizações22 slides
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
34.4K visualizações15 slides
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
3.5K visualizações13 slides

Mais procurados(20)

Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming96.2K visualizações
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman14.2K visualizações
Pointer in cPointer in c
Pointer in c
lavanya marichamy15K visualizações
Functions in CFunctions in C
Functions in C
Kamal Acharya25.1K visualizações
Operator in c programmingOperator in c programming
Operator in c programming
Manoj Tyagi34.4K visualizações
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari3.5K visualizações
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam124.5K visualizações
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav15.5K visualizações
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan70.4K visualizações
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel9.3K visualizações
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma8.4K visualizações
Structure in CStructure in C
Structure in C
Kamal Acharya35.1K visualizações
String functions in CString functions in C
String functions in C
baabtra.com - No. 1 supplier of quality freshers13.6K visualizações
File handling in cFile handling in c
File handling in c
David Livingston J28.2K visualizações
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming99K visualizações
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna13K visualizações
Operators in c languageOperators in c language
Operators in c language
Amit Singh5.6K visualizações
Strings in CStrings in C
Strings in C
Kamal Acharya23.8K visualizações
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi208.1K visualizações
C if elseC if else
C if else
Ritwik Das13.7K visualizações

Destaque

Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
680 visualizações18 slides
Learning the C LanguageLearning the C Language
Learning the C LanguagenTier Custom Solutions
2.4K visualizações188 slides
Arithmetic operatorArithmetic operator
Arithmetic operatorJordan Delacruz
4.9K visualizações17 slides
Learn CLearn C
Learn Ckantila
4.5K visualizações88 slides
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
8.9K visualizações18 slides

Destaque(18)

Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha680 visualizações
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions2.4K visualizações
Arithmetic operatorArithmetic operator
Arithmetic operator
Jordan Delacruz4.9K visualizações
Learn CLearn C
Learn C
kantila4.5K visualizações
Types of operators in CTypes of operators in C
Types of operators in C
Prabhu Govind8.9K visualizações
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
Vivek chan5.7K visualizações
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak5.2K visualizações
Autonomous RC car using gpsAutonomous RC car using gps
Autonomous RC car using gps
ma_np2.9K visualizações
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
Olve Maudal5.5K visualizações
Advance Microcontroller AVRAdvance Microcontroller AVR
Advance Microcontroller AVR
Daksh Raj Chopra5.9K visualizações
AVR FundamentalsAVR Fundamentals
AVR Fundamentals
Vinit Vyas25.9K visualizações
Introduction to AVR Microcontroller Introduction to AVR Microcontroller
Introduction to AVR Microcontroller
Mahmoud Sadat11.1K visualizações
Arithmetic Logic Unit (ALU)Arithmetic Logic Unit (ALU)
Arithmetic Logic Unit (ALU)
Student32.2K visualizações
AVR MicrocontrollerAVR Microcontroller
AVR Microcontroller
Özcan Acar11.7K visualizações
Avr introductionAvr introduction
Avr introduction
Anant Shrivastava7.7K visualizações
AVR programming - BASICSAVR programming - BASICS
AVR programming - BASICS
Robotix 201137.8K visualizações
Deep CDeep C
Deep C
Olve Maudal871.4K visualizações

Similar a Operators in C Programming

PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxNithya K
3 visualizações18 slides
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
2 visualizações7 slides
2. operator2. operator
2. operatorShankar Gangaju
114 visualizações10 slides

Similar a Operators in C Programming(20)

ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
Amrinder Sidhu377 visualizações
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
Nithya K3 visualizações
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY202 visualizações
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley2 visualizações
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
CGC Technical campus,Mohali97 visualizações
2. operator2. operator
2. operator
Shankar Gangaju114 visualizações
Theory3Theory3
Theory3
Dr.M.Karthika parthasarathy258 visualizações
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
Saranya saran52 visualizações
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur50 visualizações
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
REHAN IJAZ119 visualizações
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
Pradipta Mishra584 visualizações
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra529 visualizações
Programming in CProgramming in C
Programming in C
Nishant Munjal489 visualizações
Operators1.pptxOperators1.pptx
Operators1.pptx
HARSHSHARMA8402 visualizações
OPERATORS.pptxOPERATORS.pptx
OPERATORS.pptx
PMLAVANYA111 visualizações
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .50 visualizações
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzation
Kaushal Patel5.6K visualizações
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar288 visualizações
Arithmetic operatorArithmetic operator
Arithmetic operator
Md Masudur Rahman315 visualizações
Unit 2Unit 2
Unit 2
DURGADEVIP72 visualizações

Último(20)

Hands-On Workshop Chat GPT (Intro-B4-Practical).pdfHands-On Workshop Chat GPT (Intro-B4-Practical).pdf
Hands-On Workshop Chat GPT (Intro-B4-Practical).pdf
noorishamirsyad228 visualizações
TU Delft + NEBSTAR students booklet.pdfTU Delft + NEBSTAR students booklet.pdf
TU Delft + NEBSTAR students booklet.pdf
mimiramirez845 visualizações
How to present dataHow to present data
How to present data
Pavel Šabatka41 visualizações
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com67 visualizações
ICDE OERAC_CostaRica2023_OER_AI_Final7Nov2023.pptx.pdfICDE OERAC_CostaRica2023_OER_AI_Final7Nov2023.pptx.pdf
ICDE OERAC_CostaRica2023_OER_AI_Final7Nov2023.pptx.pdf
Ebba Ossiannilsson41 visualizações
Streaming Quiz 2023.pdfStreaming Quiz 2023.pdf
Streaming Quiz 2023.pdf
Quiz Club NITW77 visualizações
NS3 Unit 2 Life processes of animals.pptxNS3 Unit 2 Life processes of animals.pptx
NS3 Unit 2 Life processes of animals.pptx
manuelaromero201368 visualizações
ICS3211_lecture_week72023.pdfICS3211_lecture_week72023.pdf
ICS3211_lecture_week72023.pdf
Vanessa Camilleri175 visualizações
Marilyn And Len Exchanges, EssayMarilyn And Len Exchanges, Essay
Marilyn And Len Exchanges, Essay
Melissa Dudas69 visualizações
discussion post.pdfdiscussion post.pdf
discussion post.pdf
jessemercerail57 visualizações
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
Tariq KHAN149 visualizações
class-3   Derived lipids (steorids).pptxclass-3   Derived lipids (steorids).pptx
class-3 Derived lipids (steorids).pptx
Dr. Santhosh Kumar. N45 visualizações
Scope of Biochemistry.pptxScope of Biochemistry.pptx
Scope of Biochemistry.pptx
shoba shoba104 visualizações
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865452 visualizações
Material del tarjetero LEES Travesías.docxMaterial del tarjetero LEES Travesías.docx
Material del tarjetero LEES Travesías.docx
Norberto Millán Muñoz48 visualizações
Being Green Is A Popular Song By Joe RaposoBeing Green Is A Popular Song By Joe Raposo
Being Green Is A Popular Song By Joe Raposo
Kimberly Jones85 visualizações
Bb&Amp;T Bank AnalysisBb&Amp;T Bank Analysis
Bb&Amp;T Bank Analysis
Heidi Owens85 visualizações
2022 CAPE Merit List 2023 2022 CAPE Merit List 2023
2022 CAPE Merit List 2023
Caribbean Examinations Council2.3K visualizações
Azure DevOps Pipeline setup for Mule APIs #36Azure DevOps Pipeline setup for Mule APIs #36
Azure DevOps Pipeline setup for Mule APIs #36
MysoreMuleSoftMeetup66 visualizações

Operators in C Programming

  • 1. OPERATORS N.V.RAJA SEKHAR REDDY C Programming Tutorials www.programming9.com
  • 2. What is an operator?  An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.  These operators are used in programs to manipulate data and variables. 2 www.programming9.com
  • 3. Types of Operators 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators3 www.programming9.com
  • 4. ARITHMETIC OPERATORS:  Arithmetic operators are used to perform numerical calculations among the values. OPERATOR MEANING + Addition - Subtraction * Multiplication / Division % Modulo Division 4 www.programming9.com
  • 5. #include<stdio.h> int main() { int a, b, add, sub, mul, div, rem; printf("Enter a, b values : "); scanf("%d%d",&a,&b); // Reading two values add=a+b; // Addition Operator sub=a-b; // Subtraction Operator mul=a*b; // Multiplication Operator div=a/b; // Division Operator rem=a%b; // Remainder (Modulo) Operator printf("Result of addition is=%dn", add); printf("Result of subtraction=%dn", sub); printf("Result of multiplication is=%dn", mul); printf("Result of division is=%dn", div); printf("Result of remainder=%dn",rem); return 0; } 5 www.programming9.com
  • 6. RELATIONAL OPERATOR:  Relational Operators are used to compare two quantities and take certain decision depending on their relation. If the specified relation is true it returns one. If the specified relation is false it returns zero. OPERATOR MEANING < Is less than <= Is less than or equal to > Is greater than >= Is greater than or equal to == Is equal to != Is not equal to 6 www.programming9.com
  • 7. #include<stdio.h> void main() { int a, b; printf(“Enter values for a and b : "); scanf("%d %d", &a, &b); printf("n The < value of a is %d", a<b); printf("n The <= value of a is %d", a<=b); printf("n The > value of a is %d", a>b); printf("n The >= value of a is %d", a>=b); printf("n The == value of a is %d", a==b); printf("n The != value of a is %d", a!=b); } 7 www.programming9.com Example Program
  • 8. LOGICAL OPERATORS:  These operators are used for testing more than one condition and making decisions. 'c' has three logical operators they are: OPERATOR MEANING && Logical AND || Logical OR ! Logical NOT 8 www.programming9.com
  • 9. Logical Operators Example Program #include<stdio.h> void main() { int a, b; printf(“Enter values for a and b : "); scanf(“%d %d", &a, &b); printf("n %d",(a<b)&&(a!=b)); printf("n %d",(a<b)||(b<a)); printf("n %d",!(a==b)); } 9 www.programming9.com
  • 10. ASSIGNMENT OPERATORS  These operators are used for assigning the result of an expression to a variable.  b=a; OPERATORS: ==, +=, -=, *=, /=, %=, >>=, <<=, &=, |=, ^= 10 www.programming9.com
  • 11. Assignment Operators Example #include<stdio.h> void main() { int a, b, c; printf("Enter the values for a and b : "); scanf("%d %d",&a,&b); printf("n the values of= is:%d",c=a+b); printf("n the values of +=is:%d",c+=b); printf("n the value of-= is:%d",c-=a); printf("n the value of *=is:%d",c*=a); printf("n the value of /=is:%d",c/=b); printf("n the value of %=is:%d",c%=b); } 11 www.programming9.com
  • 12. INCREMENT & DECREMENT OPERATORS Two most useful operators which are present in 'c' are increment and decrement operators. Operators: ++ and -- The operator ++ adds one to the operand The operator -- subtracts one from the operand. Both are unary operators and can be used as pre or post increment/decrement. 12 www.programming9.com
  • 13. INCREMENT & DECREMENT OPERATORS EXAMPLE #include<stdio.h> void main() { int a,b,c; printf("Enter the values for a and b :"); scanf("%d %d", &a, &b); printf("n The value of c is %d", c=++a); printf("n The value of c is %d", c=a++); printf("n The value of c is %d", c=--b); printf("n The value of c is %d", c=b--); } 13 www.programming9.com
  • 14. CONDITIONAL OPERATORS These conditional operator are used to construct conditional expressions of the form. Syntax: exp1?exp2:exp3. where exp1,exp2,exp3 are expressions. Operator: ?: (ternary operator) 14 www.programming9.com
  • 15. Conditional Operators Example #include<stdio.h> void main() { int a, b, x; printf("Enter the values of a add b : "); scanf("%d %d", &a, &b); x=(a>b)?a:b; printf("Biggest Value is :%d",x); } 15 www.programming9.com
  • 16. BITWISE OPERATORS  These operators works on bit level  Applied to Integers only OPERATOR MEANING & Bitwise AND | Bitwise OR ^ Bitwise Exclusive OR << Shift Left >> Shift Right 16 www.programming9.com
  • 17. SPECIAL OPERATORS 'C' supports some special operators such as comma operator, sizeof operator and pointer operators. Comma operator: the comma operator is used to combine related expressions. A comma linked list of expressions are evaluated left to right and the value of right most expression is the value of combined expression.. Example: value=(x=10, y=5, x+y); 17 www.programming9.com
  • 18. Special Operators Contd… Sizeof Operator: Sizeof is an operator used to return the number of bytes the operand occupies. Syntax: m=sizeof(sum); k=sizeof(2351); 18 www.programming9.com