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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.