Primitive Data Types in C++

This C++ Program which reads in the values of different primitive datatypes. The program uses input streams to take in the values of the primitive datatypes.

Here is source code of the C++ program which reads in the values of different primitive datatypes. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to Read Primitive Datatypes
  3.  */
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int integer;
  10.     char character;
  11.     float float_value;
  12.     double double_value;
  13.     bool boolean;
  14.  
  15.     cout << "Non-zero value stands for true and "
  16.          << "anything else for false " << endl;
  17.     cout << "Enter the boolean value : ";
  18.     cin  >> boolean;
  19.     cout << "Enter an integer value  : ";
  20.     cin  >> integer;
  21.     cout << "Enter the character     : ";
  22.     cin  >> character;
  23.     cout << "Enter the float value   : ";
  24.     cin  >> float_value;
  25.     cout << "Enter the double value  : ";
  26.     cin  >> double_value;
  27.     cout << endl;
  28.     cout << "Integer   : " << integer << endl
  29.          << "Character : " << character << endl
  30.          << "Float     : " << float_value << endl
  31.          << "Double    : " << double_value << endl
  32.          << "Boolean   : " << boolean;
  33. }

$ g++ main.cpp
$ ./a.out
Non-zero value stands for true and anything else for false
Enter the boolean value : 1
Enter an integer value  : 123
Enter the character     : a
Enter the float value   : 12.3
Enter the double value  : 12.333333
 
Integer   : 123
Character : a
Float     : 12.3
Double    : 12.3333
Boolean   : 1

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.