https://rentry.org/PPP2_p94

// Code derived from Stroustrup's PPP2 book
// § 4.3 Expressions
// -beginning on p 94

#include <iostream>

using std::cout;

int main()
{
  // compute area:
  int length = 20;  // a literal integer (used to initialize a variable)
  int width  = 40;
  int area   = length * width;  // a multiplication

  cout << length << '\n'  // output above variable values to console...
       << width << '\n'   //
       << area << '\n';

  length = 99;              // assign 99 to length
  area   = length * width;  // a multiplication (again)

  cout << length << '\n'  // output above variable values to console...
       << width << '\n'   //
       << area << '\n';
}

build & run:

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

UpNext

Edit
Pub: 21 Jan 2023 13:59 UTC
Edit: 29 Apr 2023 06:39 UTC
Views: 601