Conditional Operators in C Language
×


Conditional Operators in C Language

290

Conditional Operators in C Language, such as the Ternary Operator (' ?: ') provide way to make decision based on conditions.

They work similarly like a if-else statement .

If condition is true, first expression is executed. if condition is false second expression is executed.

This functionality makes code more efficient and easy to understand by simplifying the decision making process.

The Conditional Operators is called as Ternary Operator because it operates on three operands. making it different from other operators in C language.

Conditional Operators in C 

Example:

#include<stdio.h>
int main()
{
	int n = 10;
	char* output;
	output = (n%2 == 0 )? "Even" : "odd";
	printf("The number is %s \n", output);
	return 0;
}

Output:

The number is Even
In this code, if the number is even the output will be "Even", otherwise the output will be "Odd".

The ternary operator allows us to express decision making logic in a short and straightforward way.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments