https://rentry.org/PPP2_p117

// Code derived from Stroustrup's PPP2 book
// § 4.5.2 Function declarations
//  -and beginning on p 117

#include <iostream>

using std::cout;

int    square(int);   // declaration of square
double sqrt(double);  // declaration of sqrt

int main()
{
  int x = square(44);

  cout << x << '\n';  // output above variable value to console...
}

// for now 'elsewhere' is simply below the definition of main() in this codefile
//  -for library software this definition will usually be in a separate codefile

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

build & run:

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

PrevUpNext

Edit
Pub: 04 Feb 2023 05:15 UTC
Edit: 29 Apr 2023 08:31 UTC
Views: 471