Training Outcomes Within Your Budget!

We ensure quality, budget-alignment, and timely delivery by our expert instructors.

Share this Resource

Table of Contents

Data Types in C Programming Explained With Examples

Ever wondered how your computer understands and manipulates different kinds of information? The answer lies in Data Types in C Programming. From simple numbers to complex structures, C offers a variety of ways to represent data. Understanding these Data Types is crucial for writing efficient and error-free code.  

This comprehensive blog will delve into the world of Data Types in C Programming, explaining each type in detail with practical examples. By the end, you'll have a solid grasp of how to choose the right Data Type for your C programs. Let's dive in! 

Table of Contents 

1) What is Data Type in C? 

2) Illustration of Data Types in C 

3) Types of Data Types in C 

    a) Primary Data Types 

    b) Derived Data Types 

    c) Enumerated Data Types 

4) Conclusion 

What is Data Type in C? 

In C Programming, a Data Type specifies the type of data that a variable can hold. It dictates the kind of value a variable can store, the operations that can be performed on it, and how much memory the variable requires. Data Types are fundamental to programming as they help in efficient memory management and ensure that programs run correctly and predictably. 

For example, if you declare a variable as an integer (int), it means that the variable can hold whole numbers. Integers are used when you need to store values without fractional parts, such as counting the number of items or indexing arrays. The integer Data Type typically occupies 4 bytes of memory, but this can vary depending on the system architecture. 

Similarly, declaring a variable as a floating-point number (float) means it can hold numbers with fractional parts. Floating-point numbers are used when you need to store values with decimals, such as measurements, scientific calculations, or any value that requires precision. The float Data Type typically occupies 4 bytes of memory and can represent a wide range of values, though with limited precision compared to the double Data Type, which usually occupies 8 bytes. 

Data Types also define the operations that can be performed on the data and the way the data is stored in memory. For example, arithmetic operations like addition, subtraction, multiplication, and division can be performed on integer and floating-point Data Types, while characters can be manipulated using functions from the C standard library, such as toupper() and tolower(). 

Understanding Data Types is crucial for efficient programming in C. Using the appropriate Data Type for a variable not only optimises memory usage but also enhances the readability and maintainability of the code. It ensures that the operations performed on the data are valid and meaningful, reducing the likelihood of errors and improving the program's overall performance.
 

 C Programming Courses

 

Illustration of Data Types in C 

To illustrate, let's consider a simple C program:
 

#include  

int main() { 

    int age = 25; // Integer Data Type 

    char grade = 'A'; // Character Data Type 

    float height = 5.9; // Floating-point Data Type 

    double distance = 12345.6789; // Double-precision floating-point Data Type 

    printf("Age: %dn", age); 

    printf("Grade: %cn", grade); 

    printf("Height: %.2fn", height); 

    printf("Distance: %.4lfn", distance); 

    return 0; 

 

In this program, we define four variables of different Data Types and print their values. Each variable type dictates how much memory it occupies and what operations can be performed on it. 

Elevate your coding skills with our C Programming Training. Sign up now and excel in C programming! 

Types of Data Types in C 

Data Types in C are broadly categorised into four types: Primary, Derived, Pointer, and Enumerated. Let's explore each category and its subtypes. 

1) Primary Data Types in C 

Primary Data Types, also known as basic or fundamental Data Types, are the most common types used in C programming. These include integers, characters, and floating-point numbers. 

a) Int 

The int Data Type is used to store integers, which are whole numbers without a fractional part. The size of int can vary based on the system, but it typically occupies 4 bytes. 

Example:
 

#include  

 

int main() { 

    int count = 10; 

    printf("Count: %dn", count); 

    return 0; 


b) Char 

The char Data Type is used to store single characters. It typically occupies 1 byte of memory. 

Example:
 

#include  

int main() { 

    char letter = 'A'; 

    printf("Letter: %cn", letter); 

    return 0; 

}

 

c) Float 

The float Data Type is used to store floating-point numbers, which are numbers with a fractional part. It typically occupies 4 bytes of memory. 

Example:
 

#include  

 

int main() { 

    float price = 19.99; 

    printf("Price: %.2fn", price); 

    return 0; 

 

d) Double 

The double Data Type is used for double-precision floating-point numbers, which provide more precision than float. It typically occupies 8 bytes of memory. 

Example:
 

#include  

int main() { 

    double pi = 3.141592653589793; 

    printf("Pi: %.15lfn", pi); 

    return 0; 

 

Start your journey with Embedded C Programming! Sign up today and learn to build powerful embedded systems. 

2) Derived Data Types 

Derived Data Types are created from primary Data Types and include arrays, pointers, structures, and unions. 

a) Array 

An array is a collection of elements of the same Data Type stored in contiguous memory locations. Arrays allow you to store multiple values in a single variable. 

Example:
 

#include  

int main() { 

    int numbers[5] = {1, 2, 3, 4, 5}; 

    for(int i = 0; i < 5; i++) { 

        printf("Number[%d]: %dn", i, numbers[i]); 

    } 

    return 0; 

 

b) Pointer 

A pointer is a variable that stores the memory address of another variable. Pointers are powerful and flexible, allowing for dynamic memory allocation and manipulation. 

Example:
 

#include  

int main() { 

    int num = 10; 

    int *p; 

    p = # 

    printf("Address of num: %pn", p); 

    printf("Value of num: %dn", *p); 

    return 0; 

 

c) Structure 

A structure is a user-defined Data Type that allows grouping of variables of different Data Types under a single name. Structures are useful for representing complex data. 

Example:
 

#include  

struct Person { 

    char name[50]; 

    int age; 

    float height; 

}; 

int main() { 

    struct Person person1; 

    printf("Enter name: "); 

    scanf("%s", person1.name); 

    printf("Enter age: "); 

    scanf("%d", &person1.age); 

    printf("Enter height: "); 

    scanf("%f", &person1.height);

    printf("Name: %sn", person1.name); 

    printf("Age: %dn", person1.age); 

    printf("Height: %.2fn", person1.height); 

    return 0; 

 

d) Union 

A union is similar to a structure, but its members share the same memory location. This means a union can store different Data Types in the same memory space, but only one member can hold a value at any given time. 

Example:
 

#include  

union Data { 

    int i; 

    float f; 

    char str[20]; 

}; 

int main() { 

    union Data data; 

    data.i = 10; 

    printf("Data.i: %dn", data.i); 

    data.f = 220.5; 

    printf("Data.f: %.1fn", data.f); 

    strcpy(data.str, "C Programming"); 

    printf("Data.str: %sn", data.str); 

    return 0; 

}

 

e) Function  

Functions are blocks of code that perform specific tasks and can return values. Functions allow for modular and reusable code. 

Example:
 

int add(int a, int b)  

    return a + b; 

}

 

Master the fundamentals of coding—Join our C Programming Course today! 

3) Enumerated Data Types 

Enumerated Data Types (enum) allow you to define a set of named integer constants. Enums improve code readability and make it easier to manage related constants. 

Example:
 

#include  
 
enum Weekday { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; 
 
int main() { 
    enum Weekday today; 
    today = Wednesday; 
 
    if (today == Wednesday) { 
        printf("Today is Wednesday.n"); 
    } 
 
    return 0; 

 

Take your coding skills to the next level—Register for our C++ Programming Course today! 

Conclusion 

Data Types in C Programming are fundamental to understanding how to store and manipulate data effectively. By grasping the various Data Types—primary, derived, pointer, and enumerated—you can write more efficient and maintainable C programs. Whether you're dealing with integers, characters, floating-point numbers, arrays, pointers, structures, unions, or enums, knowing how each Data Type works and when to use them is crucial for any C programmer. 

Transform your career—Register for our C# and .NET Training today and master the skills needed to build robust applications! 

Frequently Asked Questions

Which are the basic Data Types in C Programming? faq-arrow

The basic Data Types in C Programming include int (integers), char (characters), float (single-precision floating-point numbers), and double (double-precision floating-point numbers). These fundamental types are used to store and manipulate basic data values. 

What are the derived Data Types in C? faq-arrow

Derived Data Types in C include arrays, pointers, structures, and unions. These types are created from the basic Data Types and allow for more complex data storage and manipulation, enabling the construction of advanced data structures and algorithms. 

What are the Other Resources and Offers Provided by The Knowledge Academy? faq-arrow

The Knowledge Academy takes global learning to new heights, offering over 30,000 online courses across 490+ locations in 220 countries. This expansive reach ensures accessibility and convenience for learners worldwide. 

Alongside our diverse Online Course Catalogue, encompassing 17 major categories, we go the extra mile by providing a plethora of free educational Online Resources like News updates, Blogs, videos, webinars, and interview questions. Tailoring learning experiences further, professionals can maximise value with customisable Course Bundles of TKA

What is The Knowledge Pass, and How Does it Work? faq-arrow

The Knowledge Academy’s Knowledge Pass, a prepaid voucher, adds another layer of flexibility, allowing course bookings over a 12-month period. Join us on a journey where education knows no bounds. 

What are the Related Courses and Blogs Provided by The Knowledge Academy? faq-arrow

The Knowledge Academy offers various C Programming Courses, including the E C# Programming Course, C Programming Course and the C++ Programming Training. These courses cater to different skill levels, providing comprehensive insights into C vs Java

Our Programming and DevOps Blogs cover a range of topics related to C Programming, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Programming skills, The Knowledge Academy's diverse courses and informative blogs have got you covered. 

Upcoming Programming & DevOps Resources Batches & Dates

Date

building C Programming
C Programming

Thu 16th Jan 2025

C Programming

Thu 6th Mar 2025

C Programming

Thu 22nd May 2025

C Programming

Thu 24th Jul 2025

C Programming

Thu 25th Sep 2025

C Programming

Thu 20th Nov 2025

C Programming

Thu 11th Dec 2025

Get A Quote

WHO WILL BE FUNDING THE COURSE?

cross

BIGGEST
Christmas SALE!

red-starWHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.