0% found this document useful (0 votes)
4 views1 page

C - Conditional Operators

Conditional operators in C, also known as ternary operators, return one value if a condition is true and another if it is false, using the syntax (Condition ? true_value : false_value). An example program demonstrates this by assigning a value to 'y' based on the condition of 'x', resulting in 'y' being 2 when 'x' equals 1. The output confirms the values of 'x' and 'y' as 1 and 2, respectively.

Uploaded by

INDIAN TECHING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

C - Conditional Operators

Conditional operators in C, also known as ternary operators, return one value if a condition is true and another if it is false, using the syntax (Condition ? true_value : false_value). An example program demonstrates this by assigning a value to 'y' based on the condition of 'x', resulting in 'y' being 2 when 'x' equals 1. The output confirms the values of 'x' and 'y' as 1 and 2, respectively.

Uploaded by

INDIAN TECHING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

C – Conditional Operators

CONDITIONAL OPERATORS IN C:

 Conditional operators return one value if condition is true and


returns another value is condition is false.
 This operator is also called as ternary operator.
Syntax : (Condition? true_value: false_value);
Example : (A > 100 ? 0 : 1);
 In above example, if A is greater than 100, 0 is returned else 1 is
returned. This is equal to if else conditional statements.

EXAMPLE PROGRAM FOR CONDITIONAL/TERNARY


OPERATORS IN C:

C
1 #include <stdio.h>
2
3
int main()
4
5{
6 int x=1, y ;
7 y = ( x ==1 ? 2 : 0 ) ;
8 printf("x value is %d\n", x);
9
printf("y value is %d", y);
}

OUTPUT:

x value is 1
y value is 2

You might also like