Year End Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now

Data Types in C

Level : Beginner
Mentor: Shailendra Chauhan
Duration : 00:03:00

What are Data Types in C?

In C, every variable has a the associated data type. It describes the types of data—integer, character, floating-point, double, etc.—that the variable is capable of storing. Different memory requirements and particular operations can be carried out on different types of data. A collection of data with fixed values, meaning, and features is referred to as a data type.

Different Types of Data Types in C

In C, there are many types of data types, including:

  • Basic Data Type
  • Derived Data Type
  • Enumeration Data Type
  • Void Data Type

Different categories of this Data Types


Basic Data Types in C

The "basic data types" in C are the basic data types integers, floats, characters, etc. that are used to represent simple values.

int

The integer data type stores whole numbers such as -1, 0, 42, etc.

char

The char data type stores single characters such as 'A', '1', and '$'. The character must be wrapped by single quotes and printed using the %c format specifier.

float

The float data type stores single-precision floating-point numbers, which can only represent decimal values with minimal precision. This data type has a size of 4 bytes, meaning it takes up 4 bytes of memory. It ranges from +/- 3.4E-38F to +/- 1.7E+308F, depending on the system's architecture.

Derived Data Types in C

In the C programming language, a derived data type is one that is formed by combining one or more basic or other derived data types.

Arrays

An array is a collection of similarly typed elements stored in sequential memory locations. Multiple values of the same type can be stored and retrieved using a single variable name.

Pointers

A pointer is a variable that keeps track of another variable's memory location. Pointers are used to access data indirectly by referencing its memory location, as well as to allocate memory dynamically.

Structure

A "structure" is a user-defined composite data type that combines variables from multiple data types under a single name. Complex data structures are created with it to represent real-world entities. To create a structure, use the struct keyword and define each of its members inside curly brackets.

Union

In C, the union data type is a user-defined datatype that allows multiple data types to be stored in the same memory address. It is comparable to a structure, with one key difference: only one of its members can be active and hold accurate information at any given time.

Enumeration Data Type in C

In C, enumeration is a user-defined data type that consists of a finite collection of named integer constants. It is commonly used to represent a group of related items with unique names. To build an enum, use the enum keyword followed by the enum's name, with a comma between the enum components. To use the enum, you must first construct a variable for it.

Void Data Type in C

When a function does not return a value or a pointer has a specific data type, C expresses this using the void data type. It is widely used in function declarations as a return type to indicate that the function does not return any values and instead executes a task without providing any results.

Size of Data Types in C

The size of the data types in C is set by the architecture's size, hence we cannot establish a universal data type size. The sizeof() operator in the C language allows you to check the size of data types.

Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this