C++ Examples - Creating Different Types of Variables
The following example demonstrates how to create variables of different types:
Example
#include<iostream>
#include<string>
using namespace std;
int main()
{
// Create variables
int myNum = 5; // Integer
float myFloatNum = 5.99; // Floating point number
double myDoubleNum = 9.98; // Double precision floating point number
char myLetter = 'D'; // Character
bool myBoolean = true; // Boolean
string myString = ""; // String
// Print variables
cout << "int: " << myNum << "n";
cout << "float: " << myFloatNum << "n";
cout << "double: " << myDoubleNum << "n";
cout << "char: " << myLetter << "n";
cout << "bool: " << myBoolean << "n";
cout << "string: " << myString << "n";
return 0;
}
The output of the above program is:
int: 5
float: 5.99
double: 9.98
char: D
bool: 1
string:
YouTip