ternary operator c++
C++
//(expression 1) ? expression 2 : expression 3
//If expression 1 evaluates to true, then expression 2 is evaluated.
int x, y = 10;
x = (y < 10) ? 30 : 40;
cout << "value of x: " << x << endl; //prints 40
// C++ program to find largest among two
// numbers using ternary operator
#include <iostream>
using namespace std;
int main()
{
// variable declaration
int n1 = 5, n2 = 10, max;
// Largest among n1 and n2
max = (n1 > n2) ? n1 : n2;
// Print the largest number
cout << "Largest number between "
<< n1 << " and "
<< n2 << " is "
<< max;
return 0;
}
<condition> ? <true-case-code> : <false-case-code>;
Also in C++:
- Title
- c++ string^ to char*
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- how to dynamically allocate an array c++
- Category
- C++
- Title
- how to use max_element in c++ with vector
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- function template
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- sub string of vector c++
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- c++ evaluate expression
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- array as parameter c++
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- gfg left view of tree
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- hashing in competitive programming
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- how to convert number to string
- Category
- C++
- Title
- for each c++
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- gfg bottom view of tree
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- length of 2d array c++
- Category
- C++
- Title
- C++ sfinae
- Category
- C++
- Title
- check if intent has extras
- Category
- C++
- Title
- struct c++
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- create a bitset of 1024 bits,
- Category
- C++
- Title
- how to take input in C++ in coding
- Category
- C++
- Title
- adding element in vector c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- sort function in cpp
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- new class * [] c++
- Category
- C++
- Title
- ue4 c++ array
- Category
- C++
- Title
- single line if c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- number of islands leetcode code
- Category
- C++