Integer Variables


Integer variables are used to store whole numbers
values like 1,2,3,457, 999, -1,-348 NOT anything with a decimal point 22.3 or 3.14 CANNOT be stored in an integer varable the standard ineger types are char int unsigned int long int unsiged long int long long int unsigend long long int File: main1.cpp


#include "cmpslib19.h"  // general purpose functions for use in this class

/* the macros that define the min and max values for the standard data types are in 
   <limits.h>  so we will include it */

#include <limits.h>




int main()
{

	// the int data type can hold only whole numbers 1,2,3  NOT 1.1 or 3.14 , just whole numbers
	cout << "\n\ndatatype int" << endl;
	int iTemp;

	/* 
	   since we did not initilaze iTemp with a value we have no idea what the value is.
	   do not make any assumptions it can literally be any value


	   our Makefiles use the option -Wall  to include all warnings and you will get a warning like 
	   main1.cpp:22:40: warning: 'iTemp' is used uninitialized in this function [-Wuninitialized]
	   */




	iTemp = INT_MIN; 

	cout << "the mininum value of iTemp is " << iTemp << endl;

	iTemp = INT_MAX; 

	cout << "the maximum value of iTemp is " << iTemp << endl;

	cout << "you will notice that the range of potential values is split, half negative , half positive" << endl;

	cout << "an int requires " << sizeof(int) << " bytes of memory\n";




	cout << "\n\ndatatype unsigned int" << endl;

	unsigned int uiTemp;

	uiTemp = 0; // the minimum value of any unsiged dataype is 0

	cout << "the minimum value of uiTemp is " << uiTemp << endl;

	uiTemp = UINT_MAX;

	cout << "the maximum value of uiTemp is " << uiTemp << endl;

	cout << "you will notice that the range of potential values start at zero and the largest number is much larger than that on a standard int" << endl;

	cout << "an unsigned int requires " << sizeof(unsigned int) << " bytes of memory " << endl;

	cout << "if you know you will only be needing to store positive numbers an unsigned int will allow you to store larger numbers in the same amount of memory as an int" << endl;




	cout << "\n\ndatatype long int" << endl;

	long int liTemp = LONG_MIN;

	cout << "the mininum value of liTemp is " << liTemp << endl;

	liTemp = LONG_MAX;

	cout << "the maximum value of liTemp is " << liTemp << endl;

	cout << "you will notice that the range of potential values is split, half negative , half   positive" << endl;

	cout << "a long int requires " << sizeof(long int) << " bytes of memory\n";



	cout << "\n\ndatatype unsigned long int" << endl;
	unsigned long int uliTemp;

	uliTemp = 0; // the minimum value of any unsiged dataype is 0

	cout << "the minimum value of uliTemp is " << uliTemp << endl;

	uliTemp = ULONG_MAX;

	cout << "the maximum value of uliTemp is " << uliTemp << endl;

	cout << "you will notice that the range of potential values start at zero and the largest number is much larger than that of a standard long int" << endl;

	cout << "an unsigned long int requires " << sizeof(unsigned long int) << " bytes of memory " << endl;

	cout << "if you know you will only be needing to store positive numbers an unsigned long int will allow you to store larger numbers in the same amount of memory as a long  int" << endl;



    cout << "\n\ndatatype long long int" << endl;

    long long int lliTemp = LLONG_MIN;

    cout << "the mininum value of lliTemp is " << lliTemp << endl;

    lliTemp = LLONG_MAX;

    cout << "the maximum value of lliTemp is " << lliTemp << endl;

    cout << "you will notice that the range of potential values is split, half negative , half   positive" << endl;

    cout << "a long long int requires " << sizeof(long long int) << " bytes of memory\n";



    cout << "\n\ndatatype unsigned long long int" << endl;
    unsigned long long int ulliTemp;

    ulliTemp = 0; // the minimum value of any unsiged dataype is 0

    cout << "the minimum value of ulliTemp is " << ulliTemp << endl;

    ulliTemp = ULLONG_MAX;
             
    cout << "the maximum value of ulliTemp is " << ulliTemp << endl;

    cout << "you will notice that the range of potential values start at zero and the largest    number is much larger than that of a standard long long int" << endl;

    cout << "an unsigned long long int requires " << sizeof(unsigned long long int) << " bytes of memory " << endl;

    cout << "if you know you will only be needing to store positive numbers an unsigned long long int will allow you to store larger numbers in the same amount of memory as a long long  int" << endl;





	return 0;
}

File: output1.txt



datatype int
the mininum value of iTemp is -2147483648
the maximum value of iTemp is 2147483647
you will notice that the range of potential values is split, half negative , half positive
an int requires 4 bytes of memory


datatype unsigned int
the minimum value of uiTemp is 0
the maximum value of uiTemp is 4294967295
you will notice that the range of potential values start at zero and the largest number is much larger than that on a standard int
an unsigned int requires 4 bytes of memory 
if you know you will only be needing to store positive numbers an unsigned int will allow you to store larger numbers in the same amount of memory as an int


datatype long int
the mininum value of liTemp is -9223372036854775808
the maximum value of liTemp is 9223372036854775807
you will notice that the range of potential values is split, half negative , half   positive
a long int requires 8 bytes of memory


datatype unsigned long int
the minimum value of uliTemp is 0
the maximum value of uliTemp is 18446744073709551615
you will notice that the range of potential values start at zero and the largest number is much larger than that of a standard long int
an unsigned long int requires 8 bytes of memory 
if you know you will only be needing to store positive numbers an unsigned long int will allow you to store larger numbers in the same amount of memory as a long  int


datatype long long int
the mininum value of lliTemp is -9223372036854775808
the maximum value of lliTemp is 9223372036854775807
you will notice that the range of potential values is split, half negative , half   positive
a long long int requires 8 bytes of memory


datatype unsigned long long int
the minimum value of ulliTemp is 0
the maximum value of ulliTemp is 18446744073709551615
you will notice that the range of potential values start at zero and the largest    number is much larger than that of a standard long long int
an unsigned long long int requires 8 bytes of memory 
if you know you will only be needing to store positive numbers an unsigned long long int will allow you to store larger numbers in the same amount of memory as a long long  int

for floating point values we use float double long double File: main2.cpp


#include "cmpslib19.h"  // general purpose functions for use in this class

/* the macros that define the min and max values for the standard floating pofloat  data types are in 
   <float.h>  so we will include it */

#include <float.h>



int main()
{

	cout << "\n\ndatatype float" << endl;

	float fTemp;

	fTemp = FLT_MIN; 

	cout << "the mininum value of fTemp is " << fTemp << endl;

	fTemp = FLT_MAX; 

	cout << "the maximum value of fTemp is " << fTemp << endl;

	cout << "an float requires " << sizeof(int) << " bytes of memory\n";



	cout << "\n\ndatatype double" << endl;

	double dTemp;

	dTemp = DBL_MIN; 

	cout << "the mininum value of dTemp is " << dTemp << endl;

	dTemp = DBL_MAX; 

	cout << "the maximum value of dTemp is " << dTemp << endl;

	cout << "an double requires " << sizeof(double) << " bytes of memory\n";


	cout << "\n\ndatatype long double" << endl;

	long double ldTemp;

	ldTemp = LDBL_MIN; 

	cout << "the mininum value of ldTemp is " << ldTemp << endl;

	ldTemp = LDBL_MAX; 

	cout << "the maximum value of ldTemp is " << ldTemp << endl;

	cout << "a long double requires " << sizeof(long double) << " bytes of memory\n";



	return 0;
}

File: output2.txt



datatype float
the mininum value of fTemp is 1.17549e-38
the maximum value of fTemp is 3.40282e+38
an float requires 4 bytes of memory


datatype double
the mininum value of dTemp is 2.22507e-308
the maximum value of dTemp is 1.79769e+308
an double requires 8 bytes of memory


datatype long double
the mininum value of ldTemp is 3.3621e-4932
the maximum value of ldTemp is 1.18973e+4932
a long double requires 16 bytes of memory