C++ Example - Creating Different Types of Variables
The following example demonstrates how to create different types of variables:
Example
#include <iostream>
#include <string>
using namespace std;
int main () {
// Creating variables
int myNum = 5; // Integer
float myFloatNum = 5.99; // Float
double myDoubleNum = 9.98; // Double
char myLetter = 'D'; // Character
bool myBoolean = true; // Boolean
string myString = "tutorialpro"; // String
// Printing 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: tutorialpro