Examples of integer, float, and double numbers are given below. An integer is just a whole number (no decimals). A float is a number with up to 7 decimal digits and a double is up to 15 decimal digits of precision.
// numbers.cpp
#include <iostream>
int main()
{
int a = 9;
float b = 3.14;
double c = 3.14159;
std::cout << "a is " << a << std::endl;
std::cout << "b is " << b << std::endl;
std::cout << "c is " << c << std::endl;
return 0;
}
The above code example will print the output shown below.
a is 9
b is 3.14
c is 3.14159
Gavin Wiggins © 2024.
Made on a Mac with Genja. Hosted on GitHub Pages.