What are Datatypes and modifiers in C++?
A datatype is used to restrict the variable with the type of data to be stored. Hence, one can define datatype as a way to tell the variables to store a particular type of data.
A compiler permanently stores the variable according to its datatype because it assigns a particular amount of memory. Each datatype requires a different amount of memory. For a particular Operating System architecture, int stores 4 bytes of data and char stores 1 byte of data.
When you create a variable, the first question that comes to mind is what type of values I am going to store and use. Let’s say you want to store your name in a variable. Then you will use respective predefined datatypes like char. Similarly, if you want to store or compute numbers, you may use int, double, float, etc. So lets us see what datatypes are defined in Programming World.
Categories of Data Types
Data types are mainly classified into 3 types:
- Primitive Data Types: These data types are either built-in or predefined and are used directly while programming by the programmer. For example, int, char, float, bool, etc. These data types are available in ranges like:
- Integer
- Boolean
- Double Floating point
- Character
- Null
- Character
- Derived Data Types: These are made from the primitive or built-in datatype, they mainly range from function, array, pointer and References. For example,
int a = sum(a,b); // here sum is a derived data type.
3. User-Defined Data Types: These data types are defined by the user. These mainly consist of class, structure ( struct ), Union, TypeDef and Enumeration (Enum). These data types are used and defined according to the user requirements.
What Are Modifiers in Data Type?
Modifiers in data types refer to keywords or attributes that can be added to modify the behaviour or properties of a data type. These modifiers affect how the data type is stored, displayed, and used in programming languages.

Here are some common modifiers for data types:
Signed/Unsigned: Used with integer data types, such as “int”. Signed allows both positive and negative values, while unsigned only allows positive values.
Short/Long: Used with integer data types. “Short” reduces the range of values that a variable can hold, while “long” increases it.
Float/Double: Floating-point data types can have modifiers like “float” and “double”. “Float” represents single-precision floating-point numbers, while “double” represents double-precision floating-point numbers with greater precision.
Const: Adding the “const” modifier to a variable declaration makes it read-only and prevents its value from being changed once assigned.
Volatile: The “volatile” modifier is used for variables whose value might be modified by something external to the program, such as hardware changes or interrupt service routines.
Static: The “static” modifier is used to specify that a variable retains its value between function calls. It also modifies the scope of the variable.
Public/Private/Protected: These access modifiers control the visibility and accessibility of variables or functions within classes or objects. Public means they are accessible from anywhere; private limits access to within their own class; protected allows access within their own class and derived classes.
Nullable: In some programming languages, variables can have a modifier like “?” to indicate they can accept