/////////////////////////////////////////////////////////////// // exmp1d.cpp - basic data types in C and C++ // // // // Jim Fawcett, ELE591\791, Su'99 // // // // build: cl /GX exmp1d.cpp // /////////////////////////////////////////////////////////////// #include // C++ terminal I/O library #include // C++ stream manipulator library for setw() using namespace std; void main() { cout << "\n Testing Basic Data Types " << "\n ========================== \n\n"; bool b = true; // boolean char c = 'z'; // character short int si = 3; // short integer int i = -30000; // integer long int li = 1000001L; // long integer unsigned int ui = 30000; // unsigned integer float f = 1.0F/3.0F; // floating point double d = 1.0/3.0; // double precision floating point long double ld = 1.0L/3.0L; // long double precision floating point double *pd = &d; // pointer to a double double &rd = d; // reference to a double cout.precision(12); // for floating point & double precision numbers: // set number of digits displayed after decimal cout.setf(ios::boolalpha); // display bool values with strings "true" or "false" cout << " bool b: " << b << '\n' << " char c: " << c << '\n' << " short int si: " << si << '\n' << " int i: " << i << '\n' << " long int li: " << li << '\n' << " unsigned int ui: " << ui << '\n' << " float f: " << f << '\n' << " double d: " << d << '\n' << " long double d: " << ld << '\n' << " value pointed to by pd: " << *pd << '\n' << " value referenced by rd: " << rd << "\n\n"; cout << " size of b is: " << sizeof( b) << "byte(s)\n" << " size of c is: " << sizeof( c) << "byte(s)\n" << " size of si is: " << sizeof(si) << "byte(s)\n" << " size of i is: " << sizeof( i) << "byte(s)\n" << " size of li is: " << sizeof(li) << "byte(s)\n" << " size of ui is: " << sizeof(ui) << "byte(s)\n" << " size of f is: " << sizeof( f) << "byte(s)\n" << " size of d is: " << sizeof( d) << "byte(s)\n" << " size of ld is: " << sizeof(ld) << "byte(s)\n" << " size of pd is: " << sizeof(pd) << "byte(s)\n" << " size of rd is: " << sizeof(rd) << "byte(s)\n\n"; }