https://rentry.org/PPP2_p101b

// Code derived from Stroustrup's PPP2 book
// § 4.4 Statements
// -beginning on p 101

#include <iostream>

using std::cout;

int main()
{
  int x = 4;
  int y = 7;

  if (x == 5)
    ;  // false case (does nothing)
  {
    y = 3;  // unintentional error
  }

  cout << x << '\n'  // output above variable values to console...
       << y << '\n';

  //---
  cout << '\n';  // here simply to separate the console outputs

  x = 5;  // set x to 5 now
  y = 7;  // reset y to 7

  if (x == 5)
    ;  // true case (still does nothing)
  {
    y = 3;  // accidentally "correct"
  }

  cout << x << '\n'  // output above variable values to console...
       << y << '\n';
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_04/main_p101b.cpp && ./a.out

PrevUpNext

Edit
Pub: 26 Jan 2023 07:54 UTC
Edit: 29 Apr 2023 06:56 UTC
Views: 501