---
title: "What is a ternary operator?"  
description: "What is a ternary operator?"  
author: "Shikhar Arora"  
published: 2019-12-07  
canonical: https://answers.mindstick.com/qa/92534/what-is-a-ternary-operator  
category: "technology"  
tags: ["software engineering", "programming language"]  
reading_time: 1 minute  

---

# What is a ternary operator?

What is a [ternary operator](https://www.mindstick.com/interview/1434/explain-the-ternary-conditional-operator-in-php)

## Answers

### Answer by Sangsaptak Pal

Often in a program there arrives where the triggering of a particular situation causes the execution of a particular set of statement and another set of execution for any other condition. This is the place where the use of a conditional statement arises. The ternary [operator](https://www.mindstick.com/blog/271/wildcards-operators-in-sql) (?:) is nothing but just the compressed or the shorthand version of the conditional statements like if…. else. The syntax is as follows: Expression? (value if true): (value if false) In this, if the expression evaluates to true then the first part is executed or else the second one. The expression is separated from the values with the question mark sign (?). The false and the true results are separated from each other by a colon sign (:).


---

Original Source: https://answers.mindstick.com/qa/92534/what-is-a-ternary-operator

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
