Wednesday, May 20, 2020

Short hand if-else statement in C++


  • Syntax :

     variable = (condition) ? expressionTrue : expressionFalse;

  • Program :

#include <iostream>
using namespace std;

int main() {
  cout <<"\n----------------SHORT HAND IF-ELSE STATEMENT----------------\n";
  int a;
  cout<<"\nEnter your age :";
  cin>>a;
  string c = (a < 18) ? "Minor" : "Major";
  cout << c;
  return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...