SlideShare ist ein Scribd-Unternehmen logo
Also See more posts : www.comsciguide.blogspot.com
Comma Operator :
It is a binary operator (present in between the two operands),
mainly used in two ways :
1) As a separator
2) As a operator
As a Separator :
The comma is used to separate the expressions, and as a
separator in functional calls and definitions, multiple variable
declarations, enum declarations etc, like semicolon is used to
separate the statements (i.e. terminate the statements).
int a =5 , b=6;
void fun( a , b );
As a operator :
As a operator, It evaluates its first operand and discards the
result, then it evaluates the second operand and returns the value. It
has the lowest precedence (priority) of any c operator and has the
associativity from left to right.
int j ;
j = 1, 2, 3;
j = (1, 2, 3);
Also See more posts : www.comsciguide.blogspot.com
In first statement, assignment operator (=) has high priority as
compared to comma. So the expression becomes (j = 1), 2, 3; which
implies j =1;
In second statement, bracket has highest priority than any
other operator. So comma is executed first.
1, 2 will return 2 // left to right associativity
2, 3 will return 3
Therefore j = 3;
Note :
Assigning more than one value or initialization of multiple
variables at a time will results in compilation errors.
Example:
int a = b = c = 1; and int j = 1, 2, 3; results in errors.
int a, b , c; a = b = c = 1;
int j; j = 1 , 2 , 3;
 We know that Comma operator has the lowest precedence as
compared to other operators. But in combination of semicolon
and comma, then semicolon has lowest precedence.
Also See more posts : www.comsciguide.blogspot.com
In expression a , b ; c , d it can be grouped as (a , b) ; (c , d).
 Comma operator act as a Sequence point.
int i = 3 , j = 5;
int k;
k = i++, j--;
l = j--, i++;
In the above expressions, order of evaluation is important. Both
k, l have different values. Like if we take + operator, then
k = (i++) + (j--);
l = (j--) + (i++);
Here order of evaluation is not important. Both k, l have same
values.
 Sometimes, the use of comma as separator is confused with as
operator.
void fun ( a() , b() ) // comma acts as a separator
Here we don’t consider which function is called first, as comma
just act as separator and don’t enforce any sequence. ( the standard
calling convention is always from right to left).
Example :
Printf( “ajay” , “ganesh” );
Also See more posts : www.comsciguide.blogspot.com
You may thought that, the answer should be “ganesh” ( left to
right associativity). Before evaluating the statement, we have to
check whether comma acts as an operator or separator. Here if we
consider as an operator, “ ganesh “ has to be printed.
But the output is “ajay”, because it acts as separator in function
parameters. (As I mentioned above standard calling convention,
parameters are passed from right to left ). In some books, it is also
mentioned that “In case of printf statement, once comma is read
then it will consider preceding things as variable or values for format
specifier”.
 Comma acts as an operator only in expressions.
int i = 1, j = 2; // comma acts as a separator
int i;
i = 1, 2; // comma acts as a operator
 Comma can be used to avoid a block and associated braces, as
in :
if (x == 1)
{
y = 2;
z = 3;
cout<<y<<z;
}
Also See more posts : www.comsciguide.blogspot.com
Using comma’s, the above program is also written as
if (x == 1)
y = 2, z = 3, cout<<y<<z;
For practice :
1)
int x = 10;
int y = (x++, ++x);
printf("%d", y);
2)
int x = 10, y;
y = (x++, printf("x = %dn", x), ++x, printf("x = %dn", x), x++);
printf ("y = %dn", y);
printf ("x = %dn", x);
3)
a) return a=1, b=2, c=3;
b) return (1), 2, 3;
4)
int choice = 2 ;
switch(choice)
{
case 1,2,1:
printf("ncase 1");
Also See more posts : www.comsciguide.blogspot.com
break;
case 1,3,2:
printf("ncase 2");
break;
case 4,5,3:
printf("ncase 3");
break;
}
5)
int x =1 , y =2;
if ( y > x , y < x )
printf("n y < x ");
else
printf("n x < y ");

Weitere ähnliche Inhalte

Was ist angesagt?

Basics of microstrip slot line
Basics of microstrip slot lineBasics of microstrip slot line
Basics of microstrip slot line
Darshan Bhatt
 
Horn antenna
Horn antenna Horn antenna
Horn antenna
Jiten Thapa
 
Emi emc-pdf
Emi emc-pdfEmi emc-pdf
microwave-engineering
microwave-engineeringmicrowave-engineering
microwave-engineering
ATTO RATHORE
 
Basic Electronics 3 by Dr. Mathivanan Velumani
Basic Electronics 3 by Dr. Mathivanan VelumaniBasic Electronics 3 by Dr. Mathivanan Velumani
Basic Electronics 3 by Dr. Mathivanan Velumani
Mathivanan Velumani
 
Baluns
BalunsBaluns
Baluns
Philip Evans
 
Antenna course sofia_2015_lisi_lesson1_v03
Antenna course sofia_2015_lisi_lesson1_v03Antenna course sofia_2015_lisi_lesson1_v03
Antenna course sofia_2015_lisi_lesson1_v03
Marco Lisi
 
Radiation pattern of a cell tower antenna
Radiation pattern of a cell tower antennaRadiation pattern of a cell tower antenna
Radiation pattern of a cell tower antenna
Neha Kumar
 
Half wave dipole antenna
Half wave dipole antennaHalf wave dipole antenna
Half wave dipole antenna
Roshan Kattel
 
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER 	Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
tamil arasan
 
FM Demodulation.ppt
FM Demodulation.pptFM Demodulation.ppt
FM Demodulation.ppt
ArfaQasim1
 
The experiment of the series resonant circuit
The experiment of the series resonant circuitThe experiment of the series resonant circuit
The experiment of the series resonant circuit
a-mairu
 
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
Krishanu Kundu
 
EC6602-AWP unit 1
EC6602-AWP unit 1EC6602-AWP unit 1
EC6602-AWP unit 1
krishnamrm
 
OP-AMP(OPERATIONAL AMPLIFIER)BE
OP-AMP(OPERATIONAL AMPLIFIER)BEOP-AMP(OPERATIONAL AMPLIFIER)BE
OP-AMP(OPERATIONAL AMPLIFIER)BE
Ankit Mistry
 
Varactor Diode
Varactor DiodeVaractor Diode
Varactor Diode
ayesha zaheer
 
Array antennas
Array antennasArray antennas
Array antennas
Sushant Burde
 
Microstrip rectangular patch antenna
Microstrip rectangular  patch antennaMicrostrip rectangular  patch antenna
Microstrip rectangular patch antenna
charan -
 
Band pass filter
Band pass filterBand pass filter
Band pass filter
Bangulkhanbaloch
 
loss budget calculation in fiber optic link
 loss budget calculation in fiber optic link loss budget calculation in fiber optic link
loss budget calculation in fiber optic link
JOHNSON ADEJOLA ( Msc, CCNA,CFOT, CFOS/D/H/I/O/L
 

Was ist angesagt? (20)

Basics of microstrip slot line
Basics of microstrip slot lineBasics of microstrip slot line
Basics of microstrip slot line
 
Horn antenna
Horn antenna Horn antenna
Horn antenna
 
Emi emc-pdf
Emi emc-pdfEmi emc-pdf
Emi emc-pdf
 
microwave-engineering
microwave-engineeringmicrowave-engineering
microwave-engineering
 
Basic Electronics 3 by Dr. Mathivanan Velumani
Basic Electronics 3 by Dr. Mathivanan VelumaniBasic Electronics 3 by Dr. Mathivanan Velumani
Basic Electronics 3 by Dr. Mathivanan Velumani
 
Baluns
BalunsBaluns
Baluns
 
Antenna course sofia_2015_lisi_lesson1_v03
Antenna course sofia_2015_lisi_lesson1_v03Antenna course sofia_2015_lisi_lesson1_v03
Antenna course sofia_2015_lisi_lesson1_v03
 
Radiation pattern of a cell tower antenna
Radiation pattern of a cell tower antennaRadiation pattern of a cell tower antenna
Radiation pattern of a cell tower antenna
 
Half wave dipole antenna
Half wave dipole antennaHalf wave dipole antenna
Half wave dipole antenna
 
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER 	Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
Unit II- TRANSMISSION CHARACTERISTIC OF OPTICAL FIBER
 
FM Demodulation.ppt
FM Demodulation.pptFM Demodulation.ppt
FM Demodulation.ppt
 
The experiment of the series resonant circuit
The experiment of the series resonant circuitThe experiment of the series resonant circuit
The experiment of the series resonant circuit
 
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
MASER & Parametric Amplifier in Microwave Engineering(B.Tech,ECE)
 
EC6602-AWP unit 1
EC6602-AWP unit 1EC6602-AWP unit 1
EC6602-AWP unit 1
 
OP-AMP(OPERATIONAL AMPLIFIER)BE
OP-AMP(OPERATIONAL AMPLIFIER)BEOP-AMP(OPERATIONAL AMPLIFIER)BE
OP-AMP(OPERATIONAL AMPLIFIER)BE
 
Varactor Diode
Varactor DiodeVaractor Diode
Varactor Diode
 
Array antennas
Array antennasArray antennas
Array antennas
 
Microstrip rectangular patch antenna
Microstrip rectangular  patch antennaMicrostrip rectangular  patch antenna
Microstrip rectangular patch antenna
 
Band pass filter
Band pass filterBand pass filter
Band pass filter
 
loss budget calculation in fiber optic link
 loss budget calculation in fiber optic link loss budget calculation in fiber optic link
loss budget calculation in fiber optic link
 

Ähnlich wie Comma operator

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
C operators
C operatorsC operators
C operators
GPERI
 
What is c
What is cWhat is c
What is c
pacatarpit
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
Deepak Singh
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
Mohammed Saleh
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
yasir_cesc
 
Coper in C
Coper in CCoper in C
Coper in C
thirumalaikumar3
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
Swarup Boro
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
Arpit Meena
 
C fundamental
C fundamentalC fundamental
C fundamental
Selvam Edwin
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
Swarup Kumar Boro
 
The_derivative.pdf
The_derivative.pdfThe_derivative.pdf
The_derivative.pdf
PatrickNokrek
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
rinkugupta37
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
YuvarajuCherukuri
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
dplunkett
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
sanchi29
 

Ähnlich wie Comma operator (20)

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
C operators
C operatorsC operators
C operators
 
What is c
What is cWhat is c
What is c
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Coper in C
Coper in CCoper in C
Coper in C
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
C fundamental
C fundamentalC fundamental
C fundamental
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
The_derivative.pdf
The_derivative.pdfThe_derivative.pdf
The_derivative.pdf
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
 

Mehr von Ajay Chimmani

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle
Ajay Chimmani
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans
Ajay Chimmani
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg
Ajay Chimmani
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats
Ajay Chimmani
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3
Ajay Chimmani
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERN
Ajay Chimmani
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSS
Ajay Chimmani
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1
Ajay Chimmani
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Ajay Chimmani
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4
Ajay Chimmani
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1
Ajay Chimmani
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBES
Ajay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1
Ajay Chimmani
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITY
Ajay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4
Ajay Chimmani
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERS
Ajay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2
Ajay Chimmani
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Ajay Chimmani
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2
Ajay Chimmani
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1
Ajay Chimmani
 

Mehr von Ajay Chimmani (20)

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERN
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSS
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTEREST
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBES
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITY
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERS
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1
 

Kürzlich hochgeladen

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 

Kürzlich hochgeladen (20)

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 

Comma operator

  • 1. Also See more posts : www.comsciguide.blogspot.com Comma Operator : It is a binary operator (present in between the two operands), mainly used in two ways : 1) As a separator 2) As a operator As a Separator : The comma is used to separate the expressions, and as a separator in functional calls and definitions, multiple variable declarations, enum declarations etc, like semicolon is used to separate the statements (i.e. terminate the statements). int a =5 , b=6; void fun( a , b ); As a operator : As a operator, It evaluates its first operand and discards the result, then it evaluates the second operand and returns the value. It has the lowest precedence (priority) of any c operator and has the associativity from left to right. int j ; j = 1, 2, 3; j = (1, 2, 3);
  • 2. Also See more posts : www.comsciguide.blogspot.com In first statement, assignment operator (=) has high priority as compared to comma. So the expression becomes (j = 1), 2, 3; which implies j =1; In second statement, bracket has highest priority than any other operator. So comma is executed first. 1, 2 will return 2 // left to right associativity 2, 3 will return 3 Therefore j = 3; Note : Assigning more than one value or initialization of multiple variables at a time will results in compilation errors. Example: int a = b = c = 1; and int j = 1, 2, 3; results in errors. int a, b , c; a = b = c = 1; int j; j = 1 , 2 , 3;  We know that Comma operator has the lowest precedence as compared to other operators. But in combination of semicolon and comma, then semicolon has lowest precedence.
  • 3. Also See more posts : www.comsciguide.blogspot.com In expression a , b ; c , d it can be grouped as (a , b) ; (c , d).  Comma operator act as a Sequence point. int i = 3 , j = 5; int k; k = i++, j--; l = j--, i++; In the above expressions, order of evaluation is important. Both k, l have different values. Like if we take + operator, then k = (i++) + (j--); l = (j--) + (i++); Here order of evaluation is not important. Both k, l have same values.  Sometimes, the use of comma as separator is confused with as operator. void fun ( a() , b() ) // comma acts as a separator Here we don’t consider which function is called first, as comma just act as separator and don’t enforce any sequence. ( the standard calling convention is always from right to left). Example : Printf( “ajay” , “ganesh” );
  • 4. Also See more posts : www.comsciguide.blogspot.com You may thought that, the answer should be “ganesh” ( left to right associativity). Before evaluating the statement, we have to check whether comma acts as an operator or separator. Here if we consider as an operator, “ ganesh “ has to be printed. But the output is “ajay”, because it acts as separator in function parameters. (As I mentioned above standard calling convention, parameters are passed from right to left ). In some books, it is also mentioned that “In case of printf statement, once comma is read then it will consider preceding things as variable or values for format specifier”.  Comma acts as an operator only in expressions. int i = 1, j = 2; // comma acts as a separator int i; i = 1, 2; // comma acts as a operator  Comma can be used to avoid a block and associated braces, as in : if (x == 1) { y = 2; z = 3; cout<<y<<z; }
  • 5. Also See more posts : www.comsciguide.blogspot.com Using comma’s, the above program is also written as if (x == 1) y = 2, z = 3, cout<<y<<z; For practice : 1) int x = 10; int y = (x++, ++x); printf("%d", y); 2) int x = 10, y; y = (x++, printf("x = %dn", x), ++x, printf("x = %dn", x), x++); printf ("y = %dn", y); printf ("x = %dn", x); 3) a) return a=1, b=2, c=3; b) return (1), 2, 3; 4) int choice = 2 ; switch(choice) { case 1,2,1: printf("ncase 1");
  • 6. Also See more posts : www.comsciguide.blogspot.com break; case 1,3,2: printf("ncase 2"); break; case 4,5,3: printf("ncase 3"); break; } 5) int x =1 , y =2; if ( y > x , y < x ) printf("n y < x "); else printf("n x < y ");