unsigned integer c++ code example

Example 1: difference between unsigned and signed int c++

//Difference between unsigned and signed variable types

unsigned int x; //Can hold zero & positive numbers

signed int y; //Can hold negative, zero, and positive numbers

Example 2: initialize int c++

// operating with variables

#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 5;
  b = 2;
  a = a + 1;
  result = a - b;

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

  // terminate the program:
  return 0;
}

Tags:

C Example