Operators and Expressions 43
3.3 COMMA AND CONDITIONAL OPERATOR
1) Comma operator(,) The comma operator is used to separate two or more expressions. The comma
operator has the lowest priority among all the operators. It is not essential to enclose the expressions
with comma operators within the parenthesis. For example the statements given below are valid.
Example
a=2, b=4, c=a+b;
(a=2, b=4, c= a+ b;)
The below given program illustrates the use of comma operator.
3.1 Write a program to illustrate the use of comma (,) operator.
# include <stdio.h>
# include <conio.h>
main()
{
clrscr();
printf ("Addition = %d Subtraction = %d",2+3,5-4);
i
OUTPUT;
Addition = 5
Subtraction = 1
Explanation In the above program the two equations are separated by a comma. The results are
obtained by solving the equations separated by a comma. The result obtained is printed through
printf () statement.
1) Conditional operator (?) The conditional operator contains a condition followed by two
statements or values. If the condition is true the first statement is executed otherwise the second
statement.
The conditional operator (?) and (:) are sometimes called ternary operators because they take
three arguments. The syntax of conditional operator is as given below.
Syntax
Condition ? (expressionl) : (expression2);
Two expressions are separated by a colon. If the condition is true expressionl gets evaluated
otherwise expression 2. The condition is always written before? mark.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.89.18