Another C++ program example displaying various data types

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: nil

To do: Displaying the various C++ data types in C++ programming

To show: How to print the various C++ data types in C++ programming

 

// another C++ data type program example

#include <iostream>

using namespace std;

 

// main(void) function

void main(void)

{

int p = 2000; // positive integer data type

short int q = -120; // variation

unsigned short int r = 121; // variation

float s = 21.566578; // float data type

char t = 'r'; // char data type

char name[10] = "Tom Hank"; // a string

long u = 5678; // long positive integer data type

unsigned long v = 5678; // variation

long w = -5678; // -ve long integer data type

int x = -171; // -ve integer data type

short y = -71; // short -ve integer data type

unsigned short z = 99; // variation

double a = 88.12345; // double float data type

float b = -3.245823; // float data type

 

cout<<"\t--C++ data types again--\n";

cout<<"\t-------------------\n";

cout<<"\n1. \"int\" sample: \t\t"<<p;

cout<<"\n2. \"short\" int sample: \t"<<q;

cout<<"\n3. \"unsigned short int\" sample: "<<r;

cout<<"\n4. \"float\" sample: \t\t"<<s;

cout<<"\n5. \"char\" sample: \t\t"<<t;

cout<<"\n6. \"long\" sample: \t\t"<<u;

cout<<"\n7. \"unsigned long\" sample: \t"<<v;

cout<<"\n8. negative \"long\" sample: \t"<<w;

cout<<"\n9. negative \"int\" sample: \t"<<x;

cout<<"\n10. negative \"short\" sample: \t"<<y;

cout<<"\n11. unsigned \"short\" sample: \t"<<z;

cout<<"\n12. \"double\" sample: \t\t"<<a;

cout<<"\n13. negative \"float\" sample: \t"<<b;

cout<<"\n14. \'"<<name<<"\' is a string\t"<<endl;

 

return;

}

 

Output example:

 

--C++ data types again--

-------------------

1. "int" sample: 2000

2. "short" int sample: -120

3. "unsigned short int" sample: 121

4. "float" sample: 21.5666

5. "char" sample: r

6. "long" sample: 5678

7. "unsigned long" sample: 5678

8. negative "long" sample: -5678

9. negative "int" sample: -171

10. negative "short" sample: -71

11. unsigned "short" sample: 99

12. "double" sample: 88.1235

13. negative "float" sample: -3.24582

14. 'Tom Hank' is a string

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index