https://rentry.org/PPP2_p137

// Code derived from Stroustrup's PPP2 book
// § 5.3.1 Syntax errors
//  -and beginning on p 137

#include <iostream>

using std::cout;

// calculate area of a rectangle
int area(int length, int width);

int main()
{
  int s1 = area(7;   // error: ) missing
  int s2 = area(7)   // error: ; missing
  Int s3 = area(7);  // error: Int is not a type
  int s4 = area('7); // error: non-terminated character ( ' missing)

  cout << s1 << '\n'   //
       << s2 << '\n'   //
       << s3 << '\n'   //
       << s4 << '\n';
}

int area(int length, int width) { return length * width; }

build & run:

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

UpNext

Edit
Pub: 19 Feb 2023 05:18 UTC
Edit: 29 Apr 2023 08:58 UTC
Views: 366