DATA types in C++ languages .
Data types
We already introduced data types earlier in the variables section.
Here is an example of a code with all the data types used for revision purpose.
this is the data types -
Int - 4 bytes
Float - 4 bytes
Double - 8 bytes
Char - 1 byte
Bool – 1 byte
#include <iostream>
#include <string>
using namespace std;
int main () {
// Creating variables
int _Num = 5; // Integer
float _Float = 5.99; // Floating point number
double _Double = 9.98; // Floating point number
char _Char= 'G'; // Character
bool _Bool = true; // Boolean
string _String = "Namaste"; // String
// Print variable values
cout << "int: " << _Num << "\n";
cout << "float: " << _Float << "\n";
cout << "double: " << _Double<< "\n";
cout << "char: " << _Letter << "\n";
cout << "bool: " << _Bool << "\n";
cout << "string: " << _String << "\n";
return 0;
}
What is the difference between float and Double?
Both of them differ in their size. Float occupies 4 bytes however double occupies 8 bytes. This implies they also differ in the precision they provide. The precision of float is only six decimal digits, while double variables have a precision of about 15 digits. Hence it is safer to use double unless you are concerned about how much memory is being occupied.
Comments
Post a Comment