https://rentry.org/PPP2_p111

// Code derived from Stroustrup's PPP2 book
// § 4.4.2.2 Blocks
//  -and beginning on p 111

#include <iostream>

using std::cout;

// return the square of x
int square(int x) { return x * x; }

int main()
{
  int i = 0;

  while (i < 100) {
    cout << i << '\t' << square(i) << '\n';

    ++i;  // increment i (that is, i becomes i+1)
  }

  //---
  cout << '\n';

  int a = 1;
  int b = 0;

  if (a <= b) {
    ;  // do nothing

  } else {  // swap a and b
    int t = a;
    a     = b;
    b     = t;
  }

  cout << a << '\n'  // output above variable values to console
       << b << '\n';
}

build & run:

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

PrevUpNext

Edit
Pub: 01 Feb 2023 13:42 UTC
Edit: 29 Apr 2023 08:22 UTC
Views: 466