The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
The comma operator is used to separate two or more expression. Where first expression1 is evaluated, then expression2 is evaluated, and the value of expression2 is returned for the whole expression.
#include <stdio.h> //header file section int main() //main section { int a=5, b=10; if(a>b,a<b) printf("if condition executes"); else printf("else condition executes"); return 0; }
In the above program if condition checks only the right most codition as comma operator sperates two conditions.
Comma operator has the lowest priority among all the operators.
Here is an example program where comma operator get used in printf statement.
#include <stdio.h> //header file section int main() //main section { printf("Addition of 4 + 4 is %d ", 4+4); return 0; }
Here is an example program where comma operator get used in scanf statement.
#include <stdio.h> //header file section int main() //main section { int num; printf("Enter a number : "); scanf("%d",&num); printf("you entered %d",num); return 0; }
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019