https://rentry.org/PPP2_p114

// Code derived from Stroustrup's PPP2 book
// § 4.5 Functions
//  -and beginning on p 114

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

int main()
{
  square(2);  // probably a mistake: unused return value

  int v1 = square();       // error: argument missing
  int v2 = square;         // error: parentheses missing
  int v3 = square(1, 2);   // error: too many arguments
  int v4 = square("two");  // error: wrong type of argument – int expected
}

build & run:

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

PrevUpNext

Edit
Pub: 04 Feb 2023 00:19 UTC
Edit: 29 Apr 2023 08:28 UTC
Views: 642