It kind of seems like an abstract if statement, where ? checks for truth and : is else... is that so?

Yeah, almost. It's called the "conditional operator" (sometimes not entirely accurately referred to as "the ternary operator", since it's the only ternary operator in C). It's not a statement though, it's an expression, it has a value. It evaluates to its second argument if the first argument evaluates to true, and to its third argument if it's false. Therefore

sign = (s[i] == '-') ? -1 : 1;

is equivalent to

if (s[i] == '-') {
    sign = -1;
} else {
    sign = 1;
}
Answer from user529758 on Stack Overflow
🌐
Unstop
unstop.com › home › blog › ternary (conditional) operator in c (+code examples)
Ternary (Conditional) Operator In C (+Code Examples)
December 26, 2023 - The ternary operator in C language, also known as the conditional operator, is denoted by the question mark and colon symbols, i.e., (? :). It is a powerful operator that provides a shorthand way of expressing conditional assignment statements, ...
Discussions

Question mark (?) as conditional operator
It's called a ternary operator, but no, Elixir doesn't have one. You can do this, though: if true, do: x, else: y All do blocks can be written this way, since it's just a keyword list at the end of the day. More on reddit.com
🌐 r/elixir
16
5
March 30, 2022
What is a Question Mark “?” and Colon “:” Operator Used for?
a = booleanValue ? 0 : 1; means basically if (booleanValue) { a = 0; } else { a = 1; } it is just shorter and can be used inside more complex expressions More on reddit.com
🌐 r/javahelp
11
8
June 8, 2016
Question mark in Boolean statement, Whats it actually doing? (Novice)
It doesn't do anything in this case. They could just have said: bothEven = ((n1 % 2 == 0) && (n2 % 2 == 0)) I cringe the same way when someone writes: if (b == true) It's ridiculous. Just say: if (b) More on reddit.com
🌐 r/csharp
56
26
June 11, 2018
Why am I getting these strange question marks in my output?
Boxed question mark sounds like it's printing out undisplayable characters, likely something the terminal thinks is unicode. So you are likely pointing to garbage and printing it. ch2 is what is printing as ? right? More on reddit.com
🌐 r/C_Programming
16
8
October 3, 2018
🌐
Quora
quora.com › What-does-the-question-mark-mean-in-C
What does the question mark mean in C? - Quora
Answer (1 of 7): The ‘?’ is used in ternary operator. Example: (x > y) ? x : y It can be also written as: if(x > y) { printf(“%d”,x); } else { printf(“%d”,y); } Both example are the same but the ternary operator is used for simplicity ...
🌐
Mathbits
mathbits.com › MathBits › CompSci › looping › operator2.htm
Conditional Operator for C++
Conditional Operator · You can exchange simple if-else code for a single operator the conditional operator. The conditional operator is the only C++ ternary operator (working on three values). Other operators you have seen are called binary operators (working on two values)
🌐
University of Washington
courses.washington.edu › css342 › zander › css332 › datatypes.html
C/C++ data types, basic operators, and control structures
char s[] = "hello"; Basic operators The basic operators are the same as in Java, e.g., +, -, *, /, %, ++, --, etc. The question mark operator, ?:, is also found in C++. Some people call it the ternary operator because it is the only operator in C++ (and Java) that takes three operands.
🌐
PCMAG
pcmag.com › home › encyclopedia › q
Definition of question mark | PCMag
In C programming, the question mark is used as a conditional symbol. For example, in the expression x1 ?
Find elsewhere
🌐
Silvrback
tim.silvrback.com › c-question-mark-operators
Tim Leffelman - C# Question Mark Alias and Operators
December 10, 2015 - In the case of y, it would then check e. But, in the case of z, it would return null (because c is null) without consideration for e. Basically, if you find yourself trying mix too many different question mark operators, or trying to do something other then one of the following things with the ??, then you're probably doing something wrong:
🌐
Cppreference
en.cppreference.com › w › cpp › language › operator_other.html
Other operators - cppreference.com
March 5, 2025 - The value category of a function call expression is lvalue if the function returns an lvalue reference or an rvalue reference to function, is an xvalue if the function returns an rvalue reference to object, and is a prvalue otherwise. If the function call expression is a prvalue of object type, it must have complete type except when used as the operand of decltype (or as the right operand of a built-in comma operator that is the operand of decltype)(since C++11).
🌐
freeCodeCamp
freecodecamp.org › news › how-the-question-mark-works-in-javascript
How the Question Mark (?) Operator Works in JavaScript
February 3, 2021 - By Nishant Kumar The conditional or question mark operator, represented by a ?, is one of the most powerful features in JavaScript. The ? operator is used in conditional statements, and when paired with a :, can function as a compact alternative ...
🌐
Programiz
programiz.com › c-programming › ternary-operator
C Ternary Operator (With Examples)
Become a certified C programmer. Try Programiz PRO! ... We use the ternary operator in C to run one code when the condition is true and another code when the condition is false.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › conditional-or-ternary-operator-in-c
Conditional or Ternary Operator (?:) in C - GeeksforGeeks
July 12, 2025 - Since the Conditional Operator '?:' takes three operands to work, hence they are also called ternary operators.
🌐
Wikipedia
en.wikipedia.org › wiki › Ternary_conditional_operator
Ternary conditional operator - Wikipedia
January 27, 2026 - Typical syntax for an expression using the operator is like if a then b else c or a ? b : c. One can read it aloud as "if a then b otherwise c". The form a ? b : c is the most common, but alternative syntax exists. For example, Raku uses the syntax a ?? b !! c to avoid confusion with the infix ...
🌐
W3Schools
w3schools.com › c › c_conditions_short_hand.php
C Short Hand If ... Else (Ternary Operator)
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... There is also a short-hand if...else, known as the ternary operator because it uses three operands.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › operators-in-c
Operators in C - GeeksforGeeks
Interview Questions · Examples · Quizzes · Projects · Cheatsheet · File Handling · Multithreading · Memory Layout · DSA in C · C++ Last Updated : 1 Nov, 2025 · Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables.
Published   November 1, 2025
🌐
Hero Vired
herovired.com › learning-hub › topics › ternary-operator-in-c
Ternary Operators in C : Examples and Syntax - Hero Vired
January 21, 2025 - Explore ternary & conditional operators in C with examples, syntax, and a C program to find the largest of three numbers, advantages, disadvantages, and differences.
🌐
Wikipedia
en.wikipedia.org › wiki › Regular_expression
Regular expression - Wikipedia
1 week ago - matches the entire line (because the entire line begins and ends with a double-quote) instead of matching only the first part, "Ganymede,". The aforementioned quantifiers may, however, be made lazy or minimal or reluctant, matching as few characters as possible, by appending a question mark: ".+?" matches only "Ganymede,".
🌐
BYJUS
byjus.com › gate › ternary-operator-in-c
Ternary Operator in C
August 1, 2022 - Always remember that the value_if_false and value_if_true arguments need to be of the same type. Also, they must not be full statements. Rather, they should be very simple expressions. Just like the if-else statements, the ternary operator can be ...