https://rentry.org/PPP2_p69

// Code derived from Stroustrup's PPP2 book
// § 3.5 Assignment and initialization
// -beginning on p 69

#include <iostream>

using std::cout;

int main()
{
  int a = 3;          // a starts out with the value 3
  cout << a << '\n';  //

  a = 4;              // a gets the value 4 (“becomes 4”)
  cout << a << '\n';  //

  int b = a;          // b starts out with a copy of a’s value (that is, 4)
  cout << b << '\n';  //

  b = a + 5;          // b gets the value a+5 (that is, 9)
  cout << b << '\n';  //

  a = a + 7;          // a gets the value a+7 (that is, 11)
  cout << a << '\n';  //
}

build & run:

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

PrevUpNext

Edit
Pub: 18 Jan 2023 04:55 UTC
Edit: 29 Apr 2023 06:16 UTC
Views: 487