https://rentry.org/PPP2_p113b

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

#include <iostream>

using std::cout;

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

int main()
{
  cout << square(2) << '\n';   // print 4
  cout << square(10) << '\n';  // print 100
}

build & run:

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

PrevUpNext

Edit
Pub: 03 Feb 2023 23:59 UTC
Edit: 29 Apr 2023 08:27 UTC
Views: 659