Data Types
All variables use data type during declaration to restrict the type of
data to be stored. Therefore, we can say that data types are used to tell
the variables the type of data they can store. Whenever a variable is
defined in C++, the compiler allocates some memory for that
variable based on the data type with which it is declared. Every data
type requires a different amount of memory.
C++ supports a wide variety of data types and the programmer can
select the data type appropriate to the needs of the application. Data
types specify the size and types of values to be stored.
Types Of Data Types
C++ supports the following data types:
Primary or Built-in or Fundamental data type
Derived data types
User-defined data types
Primitive Data Types
These data types are built-in or predefined data types and can be used
directly by the user to declare variables. example: int, char, float, bool,
etc.
Primitive data types available in C++ are:
Integer
Character
Boolean
Floating Point
Double Floating Point
Valueless or Void
string
1. Integer
2.Floating
Point
How To Declare Floating Point Data Type
// Floating-point data types
float e = 3.14f;
double f = 3.141592;
long double g = 3.14159265358979L;
cout << "Floating-point data types: " <<
endl;
cout << "float: " << e << endl;
cout << "double: " << f << endl;
cout << "long double: " << g << endl;
3. Character Data
Type
How To Declare ‘CHAR’ Data
Type
// Character data types
char h = 'a';
cout << "Character data types: " <<
endl;
cout << "char: " << h << endl;
Character Array
The character data type in C++ is a fundamental data type used to store a
single character. It occupies 1 byte in memory. A character array holds
multiple character values in contiguous memory locations.
Character Array & String
// DECLARING CHAR ARRAY
Char name [ ]= “ ABCDEFGHI” ;
// OR
Char name [15]= “abcdefghijk”
//size of string is 24bytes
//other way to store name is string.
//<string> header file is
String name = “this is programming class”
used under the std
namespace
Thank you