This is commonly referred to as the conditional operator, and when used like this:
condition ? result_if_true : result_if_false
… if the condition
evaluates to true
, the expression evaluates to result_if_true
, otherwise it evaluates to result_if_false
.
It is syntactic sugar, and in this case, it can be replaced with
int qempty() { if(f == r) { return 1; } else { return 0; } }
Note: Some people refer to ?:
it as “the ternary operator“, because it is the only ternary operator (i.e. operator that takes three arguments) in the language they are using.
Related Posts:
- What does the question mark character (‘?’) mean in C++?
- Does Python have a ternary conditional operator?
- What exactly does += do in python?
- Use of “instanceof” in Java [duplicate]
- Does Python have a ternary conditional operator?
- What are XAND and XOR
- ^=, -= and += symbols in Python
- What does ‘&’ do in a C++ declaration?
- assignment operator overloading in c++
- Error: “expression must have integral or unscoped enum type” [duplicate]
- Logical XOR operator in C++?
- proper name for python * operator?
- What does the percentage sign mean in Python
- Not equal to != and !== in PHP
- What is ‘\0’ in C++?
- What is a Question Mark “?” and Colon “:” Operator Used for?
- What does the percentage sign mean in Python
- What does =~ do in Perl?
- error: ‘ostream’ does not name a type
- Multiple OR or AND conditions in IF statement
- Difference between “or” and || in Ruby?
- Class template inheritance C++
- What is the difference between the dot (.) operator and -> in C++?
- Difference between “and” and && in Ruby?
- The tilde operator in C
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How do you use the ? : (conditional) operator in JavaScript?
- How do you use the ? : (conditional) operator in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- How to create a dynamic array of integers
- Linker Error C++ “undefined reference ” [duplicate]
- How is the AND/OR operator represented as in Regular Expressions?
- How do I build a graphical user interface in C++? [closed]
- C++ convert from 1 char to string?
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- Behaviour of increment and decrement operators in Python
- Is there a “not equal” operator in Python?
- What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- Why do we need virtual functions in C++?
- Why in C++ do we use DWORD rather than unsigned int? [duplicate]
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- What is the result of % in Python?
- What is the C++ function to raise a number to a power?
- outputting ascii table in C++
- What is a lambda expression in C++11?
- Vector of Vectors to create matrix
- How to use the PI constant in C++
- How to throw a C++ exception
- std::string to char*
- How to generate a random number in C++?
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- How do I find the length of an array?
- Sleep for milliseconds
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What is the effect of extern “C” in C++?
- C++ Cout & Cin & System “Ambiguous” [closed]
- lvalue required as left operand of assignment error when using C++
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- Why are #ifndef and #define used in C++ header files?
- Is there a “not equal” operator in Python?
- g++ ld: symbol(s) not found for architecture x86_64
- What exactly is the difference between “pass by reference” in C and in C++?
- How to use the PI constant in C++
- How to throw a C++ exception
- Conversion from string to char – c++
- How do I fix a “Expected Primary-expression before ‘)’ token” error?
- How to find out if an item is present in a std::vector?
- What is meant by Resource Acquisition is Initialization (RAII)?
- When to use extern “C” in simple words? [duplicate]
- What is `CString`?
- Floating point exception( core dump
- Binary Search Tree Implementation in C++ STL?