difference between static int and int code example

Example 1: difference between integer and int

Int is a primitive data type
On the other hand Integer is a wrapper class that wraps a primitive type
int into an object
Int provides less flexibility as compare to Integer as it only allows the
binary value of an integer in it. The Intege on the other hand is more
flexible in storing and manupulating in data since wrapper class inherit
object class.

Example 2: what does static int do?

#include <iostream>
using namespace std;

void fun()
{
  static int i = 10;		//static makes it global throughout the program
  i++;
  cout << i;
}

int main()
{
  fun();
  fun();
  fun();
  return 0;
}

ans: 111213

Tags:

Java Example