Selecting the correct statement

In C++ programming, and other programming languages as well, we use the switch statement to select a certain process based on the value we give to the switch statement. If the value matches with the one of the switch case, it will run the process under that case. Let's take a look at the following switch.cpp code that implements the switch statement:

    /* switch.cpp */    #include <iostream>    using namespace std;    // Function to find out    // the square of an int    int Square(int a)    {      return a * a;    }    auto main() -> int    {      cout << "[switch.cpp]" << endl;      // Initializing two int variables      int input = 2;      int output = 0;      // Passing the correct argument      // to the function      switch (input)      {        case 1:            output = Square(1); break; ...

Get Learning C++ Functional Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.