GOEDUHUB Online Courses || Last Batch Student's Projects || COVID-19 Projects(AI-ML) || Universities  ||  Placement Preparation  Subscribe our youtube channel
+91-7976731765 Free Online Tutorials || AI || ML || NLP ||  OpenCV || Python || DBMS || OOPs || DSA || Java || Linux/Unix ||  C Programming
0 like 0 dislike
11 views
in Tutorial & Interview questions by Goeduhub's Expert (8.1k points)

Evaluates its left operand, discards the resulting value, and then evaluates its rights operand and result yields the value of its rightmost operand.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8.1k points)
 
Best answer
Evaluates its left operand, discards the resulting value, and then evaluates its rights operand and result yields the value of its rightmost operand.

int x = 42, y = 42;

printf("%i\n", (x *= 2, y)); /* Outputs "42". */

The comma operator introduces a sequence point between its operands.

Note that the comma used in functions calls that separate arguments is NOT the comma operator, rather it's called a separator which is different from the comma operator. Hence, it doesn't have the properties of the comma operator.

The above printf() call contains both the comma operator and the separator.

printf("%i\n", (x *= 2, y)); /* Outputs "42". */

/*                      ^          ^ this is a comma operator */

/*                      this is a separator */

The comma operator is often used in the initialization section as well as in the updating section of a for loop. For example:

for(k = 1; k < 10; printf("\%d\\n", k), k += 2);   /*outputs the odd numbers below 9/*

/* outputs sum to first 9 natural numbers */

for(sumk = 1, k = 1; k < 10; k++, sumk += k)    

      printf("\%5d\%5d\\n", k, sumk);

Related questions

0 like 0 dislike
1 answer 6 views
0 like 0 dislike
1 answer 11 views
0 like 0 dislike
1 answer 14 views
0 like 0 dislike
1 answer 15 views

 Goeduhub:

About Us | Contact Us  © goeduhub.com Social::   |  | 
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Important Lists: List of NITsList of IITsList of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG)College ReviewsCollege Fest, Events & WorkshopsKnowledge ShareTrainees/Interns After 15-04-2020
Exams & Cutoffs: JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs || Cutoff-GATECutoff_IIT-JEECS-ScopeECE ScopeEE-Scope
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
...