C++ DATA TYPES.

K.M.S.Rasanjalee Samarakoon
5 min readOct 5, 2022

--

“C++”

C++ is a general purpose, case sensitive and free form programming language that supports object oriented, procedural and general programming. In 1980, Mr. Bjarne Stroustrup was found this programming language.

This language has different data types like other programming languages too.

C++ data types

A data type is the type of data a variable can hold. While coding, we need to use different variables to store different information. Variables are just storage locations reserved for storing values.

However, C++ is a general-purpose programming language and widely used nowadays for competitive programming.

C++ supports a wide variety of data types, and the programmer can select the data type appropriate to the needs of the application.

In C++, data types can be classified as follows,

1.Fundamental data types.

2.User defined data types.

01)Fundamental data types.

Users can use the fundamental data types to declare variables, and these are built in data types in C++. Fundamental data types present in C++ are defined below:

i)Integer (int)

ii)Character (char)

iii)Boolean (bool)

iv)Floating point (float)

v)Double floating point (double)

vi)Void

i)Integer (int)

The keyword is int and can represent integer data types. The range of integers is -2147483648 to 2147483647. Integers typically require 4 bytes of memory space.

Example:

Integers are whole numbers. They can be positive, negative or zero too. Number like -15, -2155, 1000, 25599 these all are integers. It can store only integer type of values.

ii)Character (char)

Character data type is used for storing characters and this data type is used to represent ASCII character data. The keyword char represents characters. It is typically requiring 1 byte of memory space and range from -128 to 127 or 0 to 255. Single quotes ‘ ’ are used to enclose characters in C++.

Example:

Character is associated with an integer value, therefore char data type is also considered as an integer data type.

iii)Boolean (bool)

Boolean data type is used for storing Boolean or logical values. The keyword is bool. True or False are the two possible values for the Boolean data type. These values are generally used in conditional statements and loops. The variable requires 1 byte of memory space.

Example:

Boolean values are not actually stored in the words “true” or “false”. they are stored as integers. True becomes the integer 1 and false becomes the integer 0.

iv)Floating point (float)

Float is the keyword used to hold floating point numbers. The float type can represent values ranging from approximately 1.5*10-⁴⁵ to 3.4*10³⁸. The float variable has a size of 4 bytes.

Example:

v)Double floating point (double)

Double floating point data type is used for storing double-precision floating point values or decimal values. This type is same as float. Double is the keyword used to hold floating point numbers. In here it is called double data type because it can hold the double size of data compared to the float data type.

A double has 8 bytes, which is equal to 64 bits in size. Double data can be represents in real number, decimals and minus too. It can hold 15 to 16 digits before and after the decimal point.

Example:

vi)Void

Void means without value. This data type represents a valueless entity. Variables of the void type cannot be declared. It is only used for functions, does not return a value. When used in a function parameter list, void indicates that the function takes no parameters.

02)User defined data type.

These data types are defined by the user. Apart from storing simple data like numbers, characters etc. we need to store data that is of a complex format.

User defined data types or composite data types are derived from more than one built in data type which is used to store complex data.

String.

In C++, we called string is a user defined data type. A string is a variable that stores a sequence of letters or other characters such as “Hi”

Strings are useful to holding data that can be represented in text form.

………SUMMARY………

Programming is writing computer code to create a program, in order to solve a problem and to perform a specified task by the computer. Programs consist of a series of instructions to tell a computer exactly what to do and how to do it. Programming languages are used to write programs.

C++ is a high-level computer programming language. Mr. Bjarne Stroustrap found this in 1980.

In C++, it has 7 data types. These data types divide two major groups as Fundamental data types and User defined data types. int, char, bool, float, double, void and string are these 7 data types. String is belonged to the User defined data type and int, char, bool, float, double and void is belonged to the Fundamental data type. Users can use Fundamental data types to declare variables and User defined data types defined by the user.

--

--