C++ int type signed and unsigned integers

Description

C++ int type signed and unsigned integers

#include <iostream>
using namespace std;
int main()/*from   w  ww.  j  a  v  a 2s. co m*/
{
   int intVar = 1500000000;                 //1,500,000,000
   intVar = (intVar * 10) / 10;             //result too large
   cout << "intVar = " << intVar << endl;   //wrong answer
   intVar = 1500000000;                     //cast to double
   intVar = (static_cast<double>(intVar) * 10) / 10;
   cout << "intVar = " << intVar << endl;   //right answer
   return 0;
}



PreviousNext

Related