Sunday, 4 January 2015

Variables and types

To see what variable declarations look like in action within a program, let's have a look at the entire C++ code of the example about your mental memory proposed at the beginning of this chapter:

// operating with variables

#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int h, s;
  int result;

  // process:
  h = 5;
  s = 2;
  h = h + 1;
  result = h - s;

  // print out the result:
  cout << result;

  // terminate the program:
  return 0;
} 
Output:4 

No comments:

Post a Comment