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
- How many spaces for tab character(\t)?
- How do I build a graphical user interface in C++? [closed]
- What are the differences between a pointer variable and a reference variable in C++?
- outputting ascii table in C++
- What is the effect of extern “C” in C++?
- How to make a SIMPLE C++ Makefile
- What are bitwise shift (bit-shift) operators and how do they work?
- finding dll for “The specified module could not be found”
- no matching function for call to ‘ ‘
- Read file line by line using ifstream in C++
- Convert an int to ASCII character
- When should I write the keyword ‘inline’ for a function/method?
- C++ [Error] no matching function for call to
- When does a process get SIGABRT (signal 6)?
- C++ – Decimal to binary converting
- Alternative to itoa() for converting integer to string C++?
- 1e-9 or -1e9, which one is correct?
- Returning an empty string : efficient way in c++
- Debug assertion failed. C++ vector subscript out of range
- Inheriting constructors
- Vector is not a Template?
- Displaying a vector of strings in C++
- ‘vector’ in namespace ‘std’ does not have a template type
- Floating Point Exception C++ Why and what is it?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- Writing a LinkedList destructor?
- VC++ fatal error LNK1168: cannot open filename.exe for writing
- Creating a copy constructor for a linked list
- Is there a tab equivalent of std::endl within the standard library?
- Reference — What does this symbol mean in PHP?
- Is there ‘byte’ data type in C++?
- How to return a string from a C++ function?
- C++, random number w/ range of 1-6
- What does “missing template argument” mean?
- How do conversion operators work in C++?
- What is the difference between isdigit() and isnumber()?
- Convert char* to string C++
- C++ delete vector, objects, free memory
- What does `<>` mean in Python?
- Copy a file in a sane, safe and efficient way
- c++ convert string to hex
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- What does it mean double free detected in tcache 2 while using mpz?
- Generate SHA256 in c++
- A good and basic implementation of BigInt class in C++
- What is the C equivalent to the C++ cin statement?
- c++ Read from .csv file
- Check if C++ Array is Null
- Random not declared in scope
- What does the “Expected ‘(‘ for function-style cast or type construction” error mean?
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- Comparing the values of char arrays in C++
- Creating an instance of class
- Destructor for a doubly-linked list that points to its value
- cin.ignore(numeric_limits
::max(), ‘\n’) - LLVM Compiler 2.0: Warning with “using namespace std;”
- C++ operator+ and operator+= overloading
- In c++ what does a tilde “~” before a function name signify?
- ERROR: Control may reach end of non-void function /
- Function stoi not declared
- What’s the difference between while(cin) and while(cin >> num)
- Too many arguments to function
- not declared in this scope’ when using strlen()
- Converting a Cubemap into Equirectangular Panorama
- Why is this vector iterator not incrementable?
- glibc detected : double free or corruption
- What is the best way to develop a C++ web application?
- How to install Visual Studio Build Tools 2010 on Visual Studio 2015 Community?
- Converting string to unsigned int returns the wrong result
- Visual c++ can’t open include file ‘iostream’
- c++ vector bubble sort
- compare and swap vs test and set
- Weighted random numbers
- compare and swap vs test and set
- Link error “undefined reference to `__gxx_personality_v0′” and g++ [duplicate]