C++ Example - Creating Variables of Different Types
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; //Single-precision floating-point type
double myDoubleNum = 9.98; //Double-precision floating-point type
char myLetter = 'D'; //Character type
bool myBoolean = true; //Boolean type
string myString = "Example"; //String
//Output 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 result of the above program execution is:
int: 5 float: 5.99 double: 9.98 char: D bool: 1 string: Exampleother extensions