Data Types in C and C++ with RAM Visualization

You are currently viewing Data Types in C and C++ with RAM Visualization

Data Types in C and C++

When we execute an application, it gets loaded into RAM. Inside every application, we need some memory locations to store values. To store these values, we create variables. Before creating a variable, we must decide on the set of datatypes to use in our application. In C and C++, datatypes are classified into three categories:

  1. Primitive Datatypes
  2. Derived Datatypes
  3. User Defined Datatypes

Almost every programming language includes these types of datatypes. Depending on the requirement, we can select a specific datatype.

Primitive Datatypes in C and C++

Primitive datatypes are provided by the language designer. As programmers, we can directly create variables of these datatypes. For example:

  • To store a letter (alphabet), we create a variable of type char. The size of a char is typically 1 byte.
  • To store an integer value, we create a variable of type int. The size of an int is typically 4 bytes.
  • To store a numeric value with a decimal point, we create a variable of type float, which has a size of 4 bytes.
  • To store a numeric value with a higher precision decimal point, we create a variable of type double, which has a size of 8 bytes.
  • A Boolean variable can store either true or false (1 or 0). The size of a Boolean variable is 1 bit.
  • We cannot create a variable of type void.

Example:

Visualization of RAM

When we create a variable, it is considered a data object. Each data object contains two things: L-value and R-value.

  • The L-value of the variable indicates its location, which is the address of that variable.
  • The R-value is the data stored inside that variable.

Leave a Reply