SlideShare uma empresa Scribd logo
1 de 37
Gujarat Power Engineering 
& Research Institute 
By- 
-Thawani Karan(58)
C Operators and some 
differences
OPERATORS 
 Operators are symbols which take one or more 
operands or expressions and perform arithmetic or 
logical computations. 
 Operands are variables or expressions which are 
used in conjunction with operators to evaluate the 
expression. 
 Combination of operands and operators form an 
expression.
Expressions 
Combination of Operators and Operands 
Example 2 * y + 5 
Operands 
Operators
OPERATORS 
 Expressions are sequences of operators, operands, 
and punctuators that specify a computation. 
 Evaluation of expressions is based on the operators 
that the expressions contain and the context in 
which they are used. 
 Expression can result in a value and can produce 
side effects. 
 A side effect is a change in the state of the 
execution environment.
TYPES OF OPERATORS 
-C language provides following operators:-
Arithmetic Operators 
o As the name is given, arithmetic operators perform 
arithmetic operations. 
o C language provides following arithmetic operators. 
Operator name Meaning 
+ Addition 
- Subtraction 
* Multiplication 
/ Division 
% Modulus(Reminder after division)
ARITHMETIC OPERATORS 
o These are “Binary Operators” as they take two 
operands. 
o The operands must be ”Numeric Value”. 
o When both the operands are integer , then the 
result is integer. But when one of them is floating 
point and other is integer then the result is floating 
point. 
oExcept “% ” operators, all the arithmetic operators 
can be used with any type of numeric operands(either 
operands are integer or floating point), while “%” 
operator can only be used with integer data type only.
SMALL EXAMPLE TO ILLUSTRATE THE 
USE OFARITHMETIC OPERATORS 
#include<stdio.h> 
#include<conio.h> 
Void main() 
{ 
float a=4,b=2,sum,sub,mul,div; 
clrscr(); 
sum=a+b; 
sub=a-b; 
mul=a*b; 
div=a/b; 
printf(“summation of a and b=%fnsubtractionof and b= 
%fnmultiplicationof and b=%fndivision of a and b= 
%f,sum,sub,mul,div”); 
getch(); 
}
Output of the following code will be like this: 
summation of a and b=6.000000 
subtraction of a and b=2.000000 
multiplication of a and b=8.000000 
division of a and b=2.000000
CONDITIONAL OPERATORS 
o C language provides “?” operator as a conditional 
operator. 
o These are “Ternary Operators” as they take three 
operands. 
oIt is used as shown below: 
Syntax: 
Condition ? Expression1 : Expression2 
-The statement above is equivalent to: 
if (Condition) 
Expression1 
else 
Expression2
CONDITIONAL OPERATORS 
o The operator “?” works as follows: 
o Expression1 is evaluated first. If it is 
nonzero(true), then the expression2 is evaluated and 
becomes the value of the expression. 
o If expression1 is false, expression3 is evaluated 
and its value becomes the value of the expression. 
o It is to be noted that only one of the 
expression(either expression2 or expression3) is 
evaluated. 
o Hence, there is no dought that ternary operators 
are the alternative use of “if..else” statement.
Example 1: 
if/else statement: 
if (total > 60) 
grade = ‘P’ 
else 
grade = ‘F’; 
conditional statement: 
total > 60 ? grade = ‘P’: grade = ‘F’; 
OR 
grade = total > 60 ? ‘P’: ‘F’;
Example 2: 
if/else statement: 
if (total > 60) 
printf(“Passed!!n”); 
else 
printf(“Failed!!n”); 
Conditional Statement: 
printf(“%s!!n”, total > 60? “Passed”:“Failed”);
SPECIAL OPERATORS 
o C supports some special operators such as comma 
operator, size of operator, pointer operators (& and *) 
and member selection operators( . and -> ). 
The comma operator: 
o The comma operator is used to link the related 
expressions together or in the other way, it is used to 
combine multiple statememts. 
o A comma linked list of expressions are evaluated from 
“left” to “right”.
i.e. 
SPECIAL OPERATORS 
expression_1, expression_2 
expression_1 is evaluated first 
expression_2 is evaluated second 
For Example: 
value=(x=10,y=5,x+y); 
-First assigns the value 10 to x, then assigns 5 to y, 
and finally assigns 10(i.e. 10+5) to value. 
- Since comma operator has the lowest precedence 
of all operators. 
-The parentheses are necessary. 
x = (y=3 , y+1); x = 4 ( ) needed
SPECIAL OPERATORS 
 The following table gives some examples of the uses of the comma operator. 
Statement Effects 
for (i=0; i<4; 
++i, func()); 
A for statement in which i is incremented 
and func() is called at each iteration. 
An if statement in which function func() 
is called, variable i is incremented, and 
variable i is tested against a value. The 
if (func(), + 
first two expressions within this comma 
+i, i>1 ) 
expression are evaluated before the 
{ /* ... */ } 
expression i>1. Regardless of the results 
of the first two expressions, the third is 
evaluated and its result determines 
int inum=3, Comma whether acts the as if separator, statement not is processed. 
as an 
inum2=7, inum3 
= 2; 
operator.
SIZEOF OPERATOR 
oThe sizeof is a compile time operator. 
o When used with an operand, it returns the number of 
bytes the operand occupies. 
o The operand maybe a variable, a constant or a data 
type qualifier. 
Int a,m; 
m = sizeof(a); 
Printf(“size of a in bytes is %d”,m); 
Output: 
size of a in bytes is 2
INCREMENT AND DECREMENT 
OPERATORS 
o Sometimes we need to increase or drcrease a variable 
by “one”. 
o We can do that by using assignment operator =. For 
example the statement a=a+1 or a+=1 increment the 
value of variable a by 1. 
o In the same way the statement a=a-1 or a-=1 
decrements the value of variable a by 1. 
o But C language provides “Increment and Decrement 
Operators” for this type of operations.
INCREMENT AND DECREMENT 
OPERATORS 
o These operators are “unary” as they take one operand 
only. 
o The operand can be written before of after the 
operator. 
o If a is a variable, then ++a is called “prefix increment”, 
while a++ is called postfix increment. 
o Similarly, --a is called “prefix decrement” and a– is 
called “postfix decrement”. 
Prefix ++x; or Postfix x++; 
x = x + 1;
If the ++ or – operator are used in an expression or 
assignment, then prefix notation and postfix notation 
give different values. 
a++ Post-increment. After the result is obtained, the value of 
the operand is incremented by 1. 
a++ Post-decrement. After the result is obtained, the value of 
the operand is decremented by 1. 
++a Pre-increment. The operand is incremented by 1 and its 
new value is the result of the expression. 
--a Pre-decrement. The operand is decremented by 1 and its 
new value is the result of the expression.
Simple example to understand the prefix 
and postfix increment: 
int a=9,b; 
The output would be 
b=a++; 
printf(“%dn”,a); 
10 
printf(“%d”,b); 
9 
But, if we execute this code… 
int a=9,b; 
b=++a; 
printf(“%dn”,a); 
printf(“%d”,b); 
The output would be 
10 
10
Simple example to understand the prefix 
and postfix decrement: 
int a=9,b; 
The output would be 
b=a--; 
printf(“%dn”,a); 
printf(“%d”,b); 
But, if we execute this code… 
int a=9,b; 
b=--a; 
printf(“%dn”,a); 
printf(“%d”,b); 
89 
88 
The output would be
DIFFERENCES 
Complier Interpreter 
Translates whole source code 
into object code. 
Translate land execute line 
by line of source code. 
User cannot see the result of 
program at translation time. 
User can see the result of 
program at translation time. 
It requires less main memory 
beacuase at the time of 
translation it place object 
code into secondary memory. 
Execution is not the job of 
compiler. This is the job of 
loader 
It requires less main memory 
beacuase at the time of 
translation it place object 
code into main memory and 
execute it and produce the 
result.
DIFFERENCES 
Complier Interpreter 
This process is faster than 
interpreter. 
This process is slower than 
compiler. 
Size of compiler program is 
smaller than interpreter 
beacuse it contain only 
translation procedure. 
Size of interpreter program 
is larger than compiler 
beacuse it contain two tasks 
translation as well as loading.
DIFFERENCES 
Arrays Structures 
1. An array is a collection of 
related data elements of same 
type. 
1. Structure can have elements 
of different types 
Syntax: <data_type> 
array_name[size]; 
struct struct_name 
{ 
structure element 1; 
structure element 2; 
---------- 
---------- 
structure element n; } 
2. An array is a derived data struct_var_nm; 
type 
2. A structure is a 
programmer-defined data type
DIFFERENCES 
Arrays Structures 
3. Any array behaves like a 
built-in data types. All we 
have to do is to declare an 
array variable and use it. 
3. But in the case of 
structure, first we have to 
design and declare a data 
structure before the variable 
of that type are declared and 
used. 
Array elements are accessed 
by it's position or subscript. 
Structure elements are 
accessed by its object as '.' 
operator. 
Array element access takes 
less time in comparison with 
structures. 
Structure element access 
takes more time in 
comparison with arrays.
DIFFERENCES 
Data Information 
1. Data is raw, unorganized 
facts that need to be 
processed. Data can be 
something simple and 
seemingly random and useless 
until it is organized. 
1. When data is processed, 
organized, structured or 
presented in a given context 
so as to make it useful, it is 
called Information. 
2Each student's test score is 
one piece of data 
2. The class' average score or 
the school's average score is 
the information that can be 
concluded from the given data. 
3. Data is always correct (I 
can’t be 29 years old and 62 
years old at the same time) 
3. But information can be 
wrong (there could be two 
files on me, one saying I was 
born in 1981, and one saying I 
was born in 1948).
DIFFERENCES 
Algorithm Flow chart 
1. An algorithm is a finite 
sequence of well defined 
steps for solving a 
problem in a systematic 
manner. 
1. A flow chart is a 
graphical representation 
of sequence of any 
problem to be solved by 
computer programming 
2. Difficult to show language. 
branching and looping. 
2. Easy for branching and 
looping. 
3. It does not includes 
any specific symbols. 
3. Flowchart uses specific 
symbols for specific 
reasons.
Symbols that are used to draw a 
flow chart
Start 
Read a,b 
Sum=a+b 
Print”sum= 
“,sum 
Step1: input two numbers:a,b 
Step2: sum=a+b 
Step3: print”sum= “,sum 
Step 4: Stop 
Stop 
Flow Chart: 
Algorithm:
DIFFERENCES 
System Software Application 
Software 
System software is computer 
software designed to operate 
the computer hardware and to 
provide a platform for running 
application software. 
Application software is 
computer software designed 
to help the user to perform 
specific tasks. 
It is general-purpose 
software. 
It is specific purpose 
software. 
System Software Create his 
own environment to run itself 
and run other application. 
Application Software 
performs in a environment 
which created by 
System/Operating System 
It executes all the time in 
computer. 
It executes as and when 
required.
DIFFERENCES 
System Software Application Software 
System software is essential 
for a computer 
System software is essential for 
a computer 
The number of system 
software is less than 
application software. 
The number of application 
software is much more than 
system software. 
System software is written in 
low level language 
Application software are usually 
written in high level language 
Detail knowledge of hardware 
is required. 
Detail knowledge of 
organization is required.
Call by value Call by reference 
1. call by value passes the copy 
of the variable to the function 
that process it 
1call by reference passes the 
memory reference of the 
variable (pointer) to the 
function. 
2. main () 
{ 
sum (10, 20); 
//other code... 
} 
function sum (a, b) 
{ //your code..... 
} 
2. main () 
{ 
sum (&a, &b); 
//other code... 
} 
function sum (*a, *b) 
{ //your code..... 
} 
3. call by value increases the 
memory assigned to the code 
because of the copy of variables 
at each reference 
3. whereas call by reference 
utilizes the same reference of 
variable at each reference.
#include <stdio.h> 
void call_by_value(int x) 
{ 
printf("Inside call_by_value x = %d before adding 10.n", x); 
x += 10; 
printf("Inside call_by_value x = %d after adding 10.n", x); 
} 
int main() 
{ 
int a=10; 
printf("a = %d before function call_by_value.n", a); 
call_by_value(a); 
printf("a = %d after function call_by_value.n", a); 
return 0; } 
a = 10 before function call_by_value. 
Inside call_by_value x = 10 before adding 10. 
Inside call_by_value x = 20 after adding 10. 
a = 10 after function call_by_value.
#include <stdio.h> 
void call_by_reference(int *x) 
{ 
printf("Inside call_by_reference x = %d before adding 10.n", 
*x); 
*x += 10; 
printf("Inside call_by_reference x = %d after adding 10.n", *x); 
} 
int main() 
{ 
int a=10; 
printf("a = %d before function call_by_value.n", a); 
call_by_value(a); 
printf("a = %d after function call_by_value.n", a); 
return 0; } 
a = 10 before function call_by_value. 
Inside call_by_value x = 10 before adding 10. 
Inside call_by_value x = 20 after adding 10. 
a = 20 after function call_by_referance.
C operators

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

C basics
C   basicsC   basics
C basics
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
C programming
C programmingC programming
C programming
 
C Programming
C ProgrammingC Programming
C Programming
 
Loops in c
Loops in cLoops in c
Loops in c
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Programming in c
Programming in cProgramming in c
Programming in c
 
types of loops and what is loop
types of loops and what is looptypes of loops and what is loop
types of loops and what is loop
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
2. operators in c
2. operators in c2. operators in c
2. operators in c
 
Loops c++
Loops c++Loops c++
Loops c++
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 

Destaque

c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesAAKASH KUMAR
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingChitrank Dixit
 
C Programming basics
C Programming basicsC Programming basics
C Programming basicsJitin Pillai
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C ProgrammingHimanshu Negi
 

Destaque (8)

c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data types
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
C Programming basics
C Programming basicsC Programming basics
C Programming basics
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
The Loops
The LoopsThe Loops
The Loops
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 

Semelhante a C operators

Semelhante a C operators (20)

Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
C fundamental
C fundamentalC fundamental
C fundamental
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
C program
C programC program
C program
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
What is c
What is cWhat is c
What is c
 
cprogrammingoperator.ppt
cprogrammingoperator.pptcprogrammingoperator.ppt
cprogrammingoperator.ppt
 
Unit 1
Unit 1Unit 1
Unit 1
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
programing in c PPT Gaurav Nautiyal.pptx
programing in c PPT Gaurav Nautiyal.pptxprograming in c PPT Gaurav Nautiyal.pptx
programing in c PPT Gaurav Nautiyal.pptx
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
Operators
OperatorsOperators
Operators
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 

Mais de GPERI

Receiving end circle diagram
Receiving end circle diagram Receiving end circle diagram
Receiving end circle diagram GPERI
 
Tarrif and load curves
Tarrif and load curvesTarrif and load curves
Tarrif and load curvesGPERI
 
Atm frauds
Atm fraudsAtm frauds
Atm fraudsGPERI
 
reciprocating pump
reciprocating pumpreciprocating pump
reciprocating pumpGPERI
 
Generation of A.C. voltage
Generation of A.C. voltageGeneration of A.C. voltage
Generation of A.C. voltageGPERI
 
self inductance
self inductanceself inductance
self inductanceGPERI
 
Cochran Boiler
Cochran BoilerCochran Boiler
Cochran BoilerGPERI
 
Armature Reaction
Armature Reaction Armature Reaction
Armature Reaction GPERI
 
History of Management
History of ManagementHistory of Management
History of ManagementGPERI
 

Mais de GPERI (9)

Receiving end circle diagram
Receiving end circle diagram Receiving end circle diagram
Receiving end circle diagram
 
Tarrif and load curves
Tarrif and load curvesTarrif and load curves
Tarrif and load curves
 
Atm frauds
Atm fraudsAtm frauds
Atm frauds
 
reciprocating pump
reciprocating pumpreciprocating pump
reciprocating pump
 
Generation of A.C. voltage
Generation of A.C. voltageGeneration of A.C. voltage
Generation of A.C. voltage
 
self inductance
self inductanceself inductance
self inductance
 
Cochran Boiler
Cochran BoilerCochran Boiler
Cochran Boiler
 
Armature Reaction
Armature Reaction Armature Reaction
Armature Reaction
 
History of Management
History of ManagementHistory of Management
History of Management
 

Último

Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 

Último (20)

FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 

C operators

  • 1. Gujarat Power Engineering & Research Institute By- -Thawani Karan(58)
  • 2. C Operators and some differences
  • 3. OPERATORS  Operators are symbols which take one or more operands or expressions and perform arithmetic or logical computations.  Operands are variables or expressions which are used in conjunction with operators to evaluate the expression.  Combination of operands and operators form an expression.
  • 4. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators
  • 5. OPERATORS  Expressions are sequences of operators, operands, and punctuators that specify a computation.  Evaluation of expressions is based on the operators that the expressions contain and the context in which they are used.  Expression can result in a value and can produce side effects.  A side effect is a change in the state of the execution environment.
  • 6. TYPES OF OPERATORS -C language provides following operators:-
  • 7. Arithmetic Operators o As the name is given, arithmetic operators perform arithmetic operations. o C language provides following arithmetic operators. Operator name Meaning + Addition - Subtraction * Multiplication / Division % Modulus(Reminder after division)
  • 8. ARITHMETIC OPERATORS o These are “Binary Operators” as they take two operands. o The operands must be ”Numeric Value”. o When both the operands are integer , then the result is integer. But when one of them is floating point and other is integer then the result is floating point. oExcept “% ” operators, all the arithmetic operators can be used with any type of numeric operands(either operands are integer or floating point), while “%” operator can only be used with integer data type only.
  • 9. SMALL EXAMPLE TO ILLUSTRATE THE USE OFARITHMETIC OPERATORS #include<stdio.h> #include<conio.h> Void main() { float a=4,b=2,sum,sub,mul,div; clrscr(); sum=a+b; sub=a-b; mul=a*b; div=a/b; printf(“summation of a and b=%fnsubtractionof and b= %fnmultiplicationof and b=%fndivision of a and b= %f,sum,sub,mul,div”); getch(); }
  • 10. Output of the following code will be like this: summation of a and b=6.000000 subtraction of a and b=2.000000 multiplication of a and b=8.000000 division of a and b=2.000000
  • 11. CONDITIONAL OPERATORS o C language provides “?” operator as a conditional operator. o These are “Ternary Operators” as they take three operands. oIt is used as shown below: Syntax: Condition ? Expression1 : Expression2 -The statement above is equivalent to: if (Condition) Expression1 else Expression2
  • 12. CONDITIONAL OPERATORS o The operator “?” works as follows: o Expression1 is evaluated first. If it is nonzero(true), then the expression2 is evaluated and becomes the value of the expression. o If expression1 is false, expression3 is evaluated and its value becomes the value of the expression. o It is to be noted that only one of the expression(either expression2 or expression3) is evaluated. o Hence, there is no dought that ternary operators are the alternative use of “if..else” statement.
  • 13. Example 1: if/else statement: if (total > 60) grade = ‘P’ else grade = ‘F’; conditional statement: total > 60 ? grade = ‘P’: grade = ‘F’; OR grade = total > 60 ? ‘P’: ‘F’;
  • 14. Example 2: if/else statement: if (total > 60) printf(“Passed!!n”); else printf(“Failed!!n”); Conditional Statement: printf(“%s!!n”, total > 60? “Passed”:“Failed”);
  • 15. SPECIAL OPERATORS o C supports some special operators such as comma operator, size of operator, pointer operators (& and *) and member selection operators( . and -> ). The comma operator: o The comma operator is used to link the related expressions together or in the other way, it is used to combine multiple statememts. o A comma linked list of expressions are evaluated from “left” to “right”.
  • 16. i.e. SPECIAL OPERATORS expression_1, expression_2 expression_1 is evaluated first expression_2 is evaluated second For Example: value=(x=10,y=5,x+y); -First assigns the value 10 to x, then assigns 5 to y, and finally assigns 10(i.e. 10+5) to value. - Since comma operator has the lowest precedence of all operators. -The parentheses are necessary. x = (y=3 , y+1); x = 4 ( ) needed
  • 17. SPECIAL OPERATORS  The following table gives some examples of the uses of the comma operator. Statement Effects for (i=0; i<4; ++i, func()); A for statement in which i is incremented and func() is called at each iteration. An if statement in which function func() is called, variable i is incremented, and variable i is tested against a value. The if (func(), + first two expressions within this comma +i, i>1 ) expression are evaluated before the { /* ... */ } expression i>1. Regardless of the results of the first two expressions, the third is evaluated and its result determines int inum=3, Comma whether acts the as if separator, statement not is processed. as an inum2=7, inum3 = 2; operator.
  • 18. SIZEOF OPERATOR oThe sizeof is a compile time operator. o When used with an operand, it returns the number of bytes the operand occupies. o The operand maybe a variable, a constant or a data type qualifier. Int a,m; m = sizeof(a); Printf(“size of a in bytes is %d”,m); Output: size of a in bytes is 2
  • 19. INCREMENT AND DECREMENT OPERATORS o Sometimes we need to increase or drcrease a variable by “one”. o We can do that by using assignment operator =. For example the statement a=a+1 or a+=1 increment the value of variable a by 1. o In the same way the statement a=a-1 or a-=1 decrements the value of variable a by 1. o But C language provides “Increment and Decrement Operators” for this type of operations.
  • 20. INCREMENT AND DECREMENT OPERATORS o These operators are “unary” as they take one operand only. o The operand can be written before of after the operator. o If a is a variable, then ++a is called “prefix increment”, while a++ is called postfix increment. o Similarly, --a is called “prefix decrement” and a– is called “postfix decrement”. Prefix ++x; or Postfix x++; x = x + 1;
  • 21. If the ++ or – operator are used in an expression or assignment, then prefix notation and postfix notation give different values. a++ Post-increment. After the result is obtained, the value of the operand is incremented by 1. a++ Post-decrement. After the result is obtained, the value of the operand is decremented by 1. ++a Pre-increment. The operand is incremented by 1 and its new value is the result of the expression. --a Pre-decrement. The operand is decremented by 1 and its new value is the result of the expression.
  • 22. Simple example to understand the prefix and postfix increment: int a=9,b; The output would be b=a++; printf(“%dn”,a); 10 printf(“%d”,b); 9 But, if we execute this code… int a=9,b; b=++a; printf(“%dn”,a); printf(“%d”,b); The output would be 10 10
  • 23. Simple example to understand the prefix and postfix decrement: int a=9,b; The output would be b=a--; printf(“%dn”,a); printf(“%d”,b); But, if we execute this code… int a=9,b; b=--a; printf(“%dn”,a); printf(“%d”,b); 89 88 The output would be
  • 24. DIFFERENCES Complier Interpreter Translates whole source code into object code. Translate land execute line by line of source code. User cannot see the result of program at translation time. User can see the result of program at translation time. It requires less main memory beacuase at the time of translation it place object code into secondary memory. Execution is not the job of compiler. This is the job of loader It requires less main memory beacuase at the time of translation it place object code into main memory and execute it and produce the result.
  • 25. DIFFERENCES Complier Interpreter This process is faster than interpreter. This process is slower than compiler. Size of compiler program is smaller than interpreter beacuse it contain only translation procedure. Size of interpreter program is larger than compiler beacuse it contain two tasks translation as well as loading.
  • 26. DIFFERENCES Arrays Structures 1. An array is a collection of related data elements of same type. 1. Structure can have elements of different types Syntax: <data_type> array_name[size]; struct struct_name { structure element 1; structure element 2; ---------- ---------- structure element n; } 2. An array is a derived data struct_var_nm; type 2. A structure is a programmer-defined data type
  • 27. DIFFERENCES Arrays Structures 3. Any array behaves like a built-in data types. All we have to do is to declare an array variable and use it. 3. But in the case of structure, first we have to design and declare a data structure before the variable of that type are declared and used. Array elements are accessed by it's position or subscript. Structure elements are accessed by its object as '.' operator. Array element access takes less time in comparison with structures. Structure element access takes more time in comparison with arrays.
  • 28. DIFFERENCES Data Information 1. Data is raw, unorganized facts that need to be processed. Data can be something simple and seemingly random and useless until it is organized. 1. When data is processed, organized, structured or presented in a given context so as to make it useful, it is called Information. 2Each student's test score is one piece of data 2. The class' average score or the school's average score is the information that can be concluded from the given data. 3. Data is always correct (I can’t be 29 years old and 62 years old at the same time) 3. But information can be wrong (there could be two files on me, one saying I was born in 1981, and one saying I was born in 1948).
  • 29. DIFFERENCES Algorithm Flow chart 1. An algorithm is a finite sequence of well defined steps for solving a problem in a systematic manner. 1. A flow chart is a graphical representation of sequence of any problem to be solved by computer programming 2. Difficult to show language. branching and looping. 2. Easy for branching and looping. 3. It does not includes any specific symbols. 3. Flowchart uses specific symbols for specific reasons.
  • 30. Symbols that are used to draw a flow chart
  • 31. Start Read a,b Sum=a+b Print”sum= “,sum Step1: input two numbers:a,b Step2: sum=a+b Step3: print”sum= “,sum Step 4: Stop Stop Flow Chart: Algorithm:
  • 32. DIFFERENCES System Software Application Software System software is computer software designed to operate the computer hardware and to provide a platform for running application software. Application software is computer software designed to help the user to perform specific tasks. It is general-purpose software. It is specific purpose software. System Software Create his own environment to run itself and run other application. Application Software performs in a environment which created by System/Operating System It executes all the time in computer. It executes as and when required.
  • 33. DIFFERENCES System Software Application Software System software is essential for a computer System software is essential for a computer The number of system software is less than application software. The number of application software is much more than system software. System software is written in low level language Application software are usually written in high level language Detail knowledge of hardware is required. Detail knowledge of organization is required.
  • 34. Call by value Call by reference 1. call by value passes the copy of the variable to the function that process it 1call by reference passes the memory reference of the variable (pointer) to the function. 2. main () { sum (10, 20); //other code... } function sum (a, b) { //your code..... } 2. main () { sum (&a, &b); //other code... } function sum (*a, *b) { //your code..... } 3. call by value increases the memory assigned to the code because of the copy of variables at each reference 3. whereas call by reference utilizes the same reference of variable at each reference.
  • 35. #include <stdio.h> void call_by_value(int x) { printf("Inside call_by_value x = %d before adding 10.n", x); x += 10; printf("Inside call_by_value x = %d after adding 10.n", x); } int main() { int a=10; printf("a = %d before function call_by_value.n", a); call_by_value(a); printf("a = %d after function call_by_value.n", a); return 0; } a = 10 before function call_by_value. Inside call_by_value x = 10 before adding 10. Inside call_by_value x = 20 after adding 10. a = 10 after function call_by_value.
  • 36. #include <stdio.h> void call_by_reference(int *x) { printf("Inside call_by_reference x = %d before adding 10.n", *x); *x += 10; printf("Inside call_by_reference x = %d after adding 10.n", *x); } int main() { int a=10; printf("a = %d before function call_by_value.n", a); call_by_value(a); printf("a = %d after function call_by_value.n", a); return 0; } a = 10 before function call_by_value. Inside call_by_value x = 10 before adding 10. Inside call_by_value x = 20 after adding 10. a = 20 after function call_by_referance.