Conditional or Ternary Operator (__) in C - GeeksforGeeks
Conditional or Ternary Operator (__) in C - GeeksforGeeks
:) in C - GeeksforGeeks
💡 Spotlight
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 1/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
Conditional/Ternary Operator in C
if(Expression1)
{
variable = Expression2;
}
else
{
variable = Expression3;
}
Since the Conditional Operator ‘?:’ takes three operands to work, hence they
are also called ternary operators.
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 2/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
C Step C3:Data
C Basics Results
Types will be returned.
C Operators C Input and Output C Control Flow C Functions C Arrays C St
Read
Flowchart Discuss
of Courses Practice
Conditional/Ternary Operator in C
To understand the working better, we can analyze the flowchart of the
conditional operator given below.
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 3/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
#include <stdio.h>
int main()
{
int m = 5, n = 4;
return 0;
}
Output
#include <stdio.h>
int main()
{
int yr = 1900;
Output
Conclusion
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 4/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
It reduces the line of code when the condition and statements are small.
Whether you're preparing for your first job interview or aiming to upskill in
this ever-evolving tech landscape, GeeksforGeeks Courses are your key to
success. We provide top-quality content at affordable prices, all geared
towards accelerating your growth in a time-bound manner. Join the millions
we've already empowered, and we're here to do the same for you. Don't
miss out - check it out now!
Previous Next
Similar Reads
Implementing ternary operator without C/C++ Ternary Operator - Some
any conditional statement Interesting Observations
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 5/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
Article Contributed By :
khalidbitd
K khalidbitd
sizeof operator in C
Sizeof is a much-used operator in the C. It is a compile-time unary
operator which can be used to co...Read More
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 6/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
A-143, 9th Floor, Sovereign Corporate
Tower, Sector-136, Noida, Uttar Pradesh -
201305
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Apply for Mentor
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 7/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 8/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
Accountancy Management
Business Studies HR Managament
Indian Economics Income Tax
Macroeconomics Finance
Microeconimics Economics
Statistics for Economics
Colleges Companies
Indian Colleges Admission & Campus Experiences IT Companies
Top Engineering Colleges Software Development Companies
Top BCA Colleges Artificial Intelligence(AI) Companies
Top MBA Colleges CyberSecurity Companies
Top Architecture College Service Based Companies
Choose College For Graduation Product Based Companies
PSUs for CS Engineers
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 9/10
12/3/23, 4:48 PM Conditional or Ternary Operator (?:) in C - GeeksforGeeks
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/ 10/10