Data Types

In C programming, a variable is used to store the data. Data types are used to define the type of a variable. The most commonly used data types in C are int (integer), char (character), float (floating point number), and double (double precision floating point number)

Understanding the data is important as it impacts the way it is stored or retrieved from memory. Data types can affect the memory usage, speed, and accuracy of your program.

1) Integer Types :

Integers are used to represent whole numbers without decimal points. In embedded C, several integer types are available, including:

  • int: The standard signed integer type.
  • unsigned int: An unsigned integer type that only represents positive numbers.
  • short int: A signed integer with a smaller range than int.
  • unsigned short int: An unsigned integer with a smaller range than unsigned int.
  • long int: A signed integer with an extended range.
  • unsigned long int: An unsigned integer with an extended range.

Embedded C programming also offers fixed-width integer types provided by the header

Here are some commonly used fixed-width integer types, these are present in the #include :

  • int8_t: A signed 8-bit integer type.
  • uint8_t: An unsigned 8-bit integer type.
  • int16_t: A signed 16-bit integer type.
  • uint16_t: An unsigned 16-bit integer type.
  • int32_t: A signed 32-bit integer type.
  • uint32_t: An unsigned 32-bit integer type.
  • int64_t: A signed 64-bit integer type.
  • uint64_t: An unsigned 64-bit integer type.
int num = 0;
unsigned int num = 1;
short int num = 2;
unsigned short int num = 3;
long int num = 4;
unsigned long int num = 5;

int8_t num = 6;
uint8_t num = 7;

int16_t num = 8;
uint16_t num = 9;

int32_t num = 10;
uint32_t num = 11;

int64_t num = 12;
uint64_t num = 13;

2) Floating-Point Types :

Floating-point types are used to represent real numbers, including numbers with decimal points. The two commonly used floating-point types in embedded C are:

  • float: Represents single-precision floating-point numbers.
  • double: Represents double-precision floating-point numbers with increased precision compared to float.
float fl = 1.1F;
double dl = 1.2F;

3) Bool Type :

A bool * pointer is used to store the memory address of a bool variable. By utilizing a bool * pointer, we can access and manipulate the value of a bool variable indirectly. #include   header file is a standard C library header that provides the necessary definitions for using the bool type

bool num = true;

4) Pointer Types :

Pointer types are used to store memory addresses, allowing access to data located at those addresses. Some common pointer types include:

  • int *: A pointer to an integer.
  • float *: A pointer to a float.
  • void *: A pointer to an unspecified type, commonly used for generic pointers.
  • All types of data can be a pointer type

5) Character : 

This type of data is used to store single characters like letters, symbols, or numbers. The char keyword represents this data type in C.

    char ch = 'a';

    6) Array:

    This type of data is a collection of variables with the same data type and is ideal for storing multiple values of the same type.

    int arr[5] = {1, 2, 3, 4, 5};
    char ch_arr[5] = {'A', 'B', 'C', 'D', 'E'};

    7) Structure:

    This data type enables you to group variables of different data types into a single unit, making it useful for storing data related to a single entity such as a person or object.

    struct num_s { 
    int one;
    char two;
    float three;
    };
    struct num_s num;
    num.one = 1;
    num.two = '2';
    num.three = 3.00F;