Calculating with integer constants : Introduction « Language Basics « C++ Tutorial






#include <iostream>                       
using std::cout;
using std::endl;

int main() {  
  cout << 1 + 2               << endl;  
  cout << 1 - 5                << endl;  
  cout << 1 - 2               << endl;  

  cout << 1 * 2               << endl;  
  cout << 1/3                  << endl;  
  cout << 1  3                << endl;  
  cout << 1  -3               << endl;  
  cout << -1  3               << endl;  
  cout << -1  -3              << endl;  

  cout << 1 + 2/1 - 5        << endl;  
  cout << (1 + 2)/(1 - 5)    << endl;  
  cout << 1 + 2/(1 - 5)      << endl;  
  cout << (1 + 2)/1 - 5      << endl;  

  cout << 4*5/3 + 7/3         << endl;  
  return 0;                               
}
3
-4
-1
2
0
1
1
-1
-1
-2
0
1
-2
4








1.1.Introduction
1.1.1.This is a simple C++ program
1.1.2.Calculating with integer constants
1.1.3.Working with integer variables
1.1.4.Using the assignment operator