Data Types in C | Set 2

By | February 11, 2023

Prerequisite – Data Types in C | Set 1

In C programming, data types are used to specify the type of a variable, which determines the amount of memory the variable takes up and the range of values that can be stored in that memory. The data types in C can be classified into the following categories:

 

  1. Primitive data types:
    These are the basic data types that are built into the C language and include integer types, floating-point types, and the character type.
  2. Derived data types:
    These are data types that are derived from the primitive data types, such as arrays, structures, unions, and pointers.
  3. User-defined data types:
    These are data types that are defined by the user and include enumerated types, typedefs, and function types.
  4. Void data type:
    This is a special data type that represents the absence of a value. It is used as the return type of functions that do not return a value and as the type of pointers to functions.

It is important to choose the appropriate data type for a variable based on the range of values it needs to store and the operations that need to be performed on it. The choice of data type can also impact the performance and memory usage of a program, so it is important to make informed decisions when selecting data types. For example, if a variable needs to store large values, you may use a long int or long long int data type. Similarly, if a variable needs to store fractional values, you may use a float or double data type.

The C language supports several basic data types, including:

  1. Integer data types:
    These are used to store integer values, such as whole numbers. Examples include char, short int, int, long int, and long long int.
    a. char –
    a single character, typically represented as an 8-bit integer.
    b. short int –
    a short integer, typically represented as a 16-bit integer.
    c. int –
    a standard integer, typically represented as a 32-bit integer.
    d. long int –
    a long integer, typically represented as a 64-bit integer.
    e. long long int –
    an even longer integer, typically represented as an 128-bit integer.
  2. Floating-point data types:
    These are used to store fractional values. Examples include float, double, and long double.
    a. float –
    a single-precision floating-point number, represented as a 32-bit number.
    b. double –
    a double-precision floating-point number, represented as a 64-bit number.
    c. long double –
    an extended-precision floating-point number, represented as a 128-bit number.
  3. Boolean data type:
    This is used to store a true or false value.
    a. _Bool –
    a data type that can store either 0 (false) or 1 (true).
  4. Character data type:
    This is used to store a single character.
    a. char –
    a single character, typically represented as an 8-bit integer.
  5. Void data type:
    This is used to indicate the absence of data and is often used as the return type of functions that do not return a value.
    a. void –
    a data type that indicates the absence of data.

In addition to the basic data types, C also supports derived data types, such as arrays, structures, unions, and pointers, and user-defined data types, such as enumerated types, typedefs, and function types. The choice of data type can impact the performance and memory usage of a program, so it is important to make informed decisions when selecting data types.

 

Please write comments below if you find anything incorrect, or you want to share more information about the topic discussed above. A gentle request to share this topic on your social media profile.

Author: Mithlesh Upadhyay

I hold an M.Tech degree in Artificial Intelligence (2023) from Delhi Technological University (DTU) and possess over 4 years of experience. I worked at GeeksforGeeks, leading teams and managing content, including GATE CS, Test Series, Placements, C, and C++. I've also contributed technical content to companies like MarsDev, Tutorialspoint, StudyTonight, TutorialCup, and Guru99. My skill set includes coding, Data Structures and Algorithms (DSA), and Object-Oriented Programming (OOPs). I'm proficient in C++, Python, JavaScript, HTML, CSS, Bootstrap, React.js, Node.js, MongoDB, Django, and Data Science.