Data Types in C
  • Twitter
  • Facebook
  • Snapchat
  • Instagram

Data Types in C Language: A Complete Guide

📑 On this page:
  • What are Data Types?
  • 1. Primary Data Types
  • 2. Derived Data Types
  • 3. User-Defined Data Types
  • Size of Data Types
  • Frequently Asked Questions
📚 In this tutorial, you will learn:
  • What are data types in C and why they matter
  • What are Primary Data Types (int, char, float, double, void)
  • What are Derived Data Types (arrays, functions, pointers)
  • What are User-Defined Data Types (structures, unions, enums)
  • How to check the size of each data type

What are Data Types in C?

Data types in C specify the type of data a variable can store — whether it's an integer, a floating-point number, a character, or something else. They tell the compiler how much memory to allocate and how to interpret the data.

Think of data types like containers. You wouldn't store cereal in a shoe box, right? Similarly, you need the right "container" for your data. C gives you a variety of containers — choose the one that fits your data best.

💡 Quick Definition: "A data type is a classification of data that tells the compiler how the programmer intends to use the data."

Data Types in C

Example: If you want to store employee details like name, salary, and bonus — each requires a different data type:

  • Name: "Ajay" → Character/string
  • Salary: 80000 → Integer
  • Bonus: 0.56 → Float/Double

Types of Data Types in C

1

Primary Data Types

int, char, float, double, void

2

Derived Data Types

Arrays, Functions, Pointers

3

User-Defined Data Types

Structures, Unions, Enums

1. Primary Data Types

1.1 Integer (int)

The int data type is used to store whole numbers (without a fractional part). Examples: 5, 8, 67, 2390.

Integers can be signed (positive and negative) or unsigned (only positive). The memory size depends on the compiler — 2 bytes on 32-bit, 4 bytes on 64-bit.

Syntax: int variable_name;

Example: int rs;

/* Integer program example */
#include <stdio.h>

void main()
{
    int i;
    i = 20;
    printf("\nValue of i = %d", i);
    printf("\nSize of i = %u", sizeof(i));
}

Output:
Value of i = 20
Size of i = 4

Integer Data Type Variants:

  • short int (short): 1 byte, small range
  • int: 2 or 4 bytes, intermediate range
  • long int (long): 4 bytes, large range
  • long long int (long long): 8 bytes, very large range

1.2 Character (char)

The char data type stores a single character — a letter, digit, or symbol. It uses 1 byte of memory and stores values as ASCII codes.

Syntax: char variable_name = 'c';

Example: char grade = 'A';

#include <stdio.h>

int main() {
    char ch = 'a';
    printf("\nASCII code of %c is %d", ch, ch);
    return 0;
}

Output:
ASCII code of a is 97

1.3 Float

The float data type stores real numbers with decimal points. It uses 4 bytes of memory and is a single-precision floating-point type.

#include <stdio.h>

int main() {
    float y = 427.665;
    float x = 1000.5454F;
    printf("\nValue of y = %f", y);
    printf("\nValue of x = %.2f", y);
}

Output:
Value of y = 427.665000
Value of x = 1000.55

1.4 Double

The double data type stores floating-point numbers with double precision. It uses 8 bytes of memory and can store up to 15-17 decimal digits.

1.5 Void

The void data type has no value and no size. It's used to declare functions that don't return any value.

2. Derived Data Types

2.1 Arrays

An array is a collection of elements of the same data type stored in contiguous memory locations. It's used to handle large amounts of data without declaring many variables.

Syntax: data_type array_name[size];

Example: int numbers[10];

2.2 Functions

A function is a group of statements that perform a specific task. Functions allow code reuse and make programs easier to understand.

  • Library functions: Built-in functions like printf(), scanf(), sqrt()
  • User-defined functions: Created by the programmer for specific needs

2.3 Pointers

A pointer is a variable that stores the memory address of another variable. Pointers are powerful — they enable dynamic memory allocation and efficient array manipulation.

Syntax: data_type *ptr_var;

Example: int *ptr;

3. User-Defined Data Types

3.1 Structure (struct)

A structure is a user-defined data type that groups variables of different data types into a single unit.

/* Structure to store employee details */
#include <stdio.h>
#include <string.h>

struct Employee {
    char name[50];
    int empno;
    float salary;
};

int main() {
    struct Employee emp1;
    strcpy(emp1.name, "Raj");
    emp1.empno = 1990;
    emp1.salary = 40980.99;
    return 0;
}

3.2 Union

A union is similar to a structure, but all members share the same memory location. The memory allocated is equal to the largest member.

union Emp {
    float salary;
    char name[20];
} e;

int main() {
    union Emp e;
    e.salary = 20090.034;
    strcpy(e.name, "Raj");
    return 0;
}

3.3 Enum (enum)

Enum is a user-defined data type used to assign names to integer constants, making code more readable.

enum countries {America, India, China, Japan, England, Shrilanka};

int main() {
    enum countries cnt;
    cnt = America;
    printf("%d", cnt);
    return 0;
}

Output:
0

Size of Data Types in C

The memory occupied by each data type depends on the compiler architecture (32-bit or 64-bit). Here's a typical output:

#include <stdio.h>
#include <limits.h>

int main() {
    printf("Size of short int is %2d bytes \n", sizeof(short int));
    printf("Size of int is %2d bytes \n", sizeof(int));
    printf("Size of long int is %2d bytes \n", sizeof(long int));
    printf("Size of float is %2d bytes \n", sizeof(float));
    printf("Size of double is %2d bytes \n", sizeof(double));
    printf("Size of char is %2d bytes \n", sizeof(char));
    return 0;
}

Output:
Size of short int is 2 bytes
Size of int is 4 bytes
Size of long int is 8 bytes
Size of float is 4 bytes
Size of double is 8 bytes
Size of char is 1 bytes
Data Type Memory (32-bit) Memory (64-bit) Range
short int2 bytes2 bytes-32,768 to 32,767
int2 bytes4 bytes-2,147,483,648 to 2,147,483,647
long int4 bytes8 bytes-2,147,483,648 to 2,147,483,647
float4 bytes4 bytes1.2E-38 to 3.4E+38
double8 bytes8 bytes2.3E-308 to 1.7E+308
char1 byte1 byte-128 to 127

Frequently Asked Questions About Data Types in C

1. What are the three types of data types in C?

Primary/Basic Data Types: int, char, float, double, void
Derived Data Types: arrays, functions, pointers
User-Defined Data Types: structures, unions, enums

2. What is the difference between float and double?

Float is single-precision (4 bytes) with 6-7 decimal digits. Double is double-precision (8 bytes) with 15-17 decimal digits.

3. What is the difference between structure and union?

In a structure, each member has its own memory. In a union, all members share the same memory location.

4. What is the use of void data type?

Void is used to declare functions that don't return any value. It's also used for pointers that can point to any data type.

💡 Quick tip: Choose the smallest data type that can hold your data. It saves memory and improves performance.

📖 Related Tutorials

  • Variables and Identifiers
  • Operators in C
  • Constants in C
  • Assignment Statements

Previous Topic: -->> Variables and Identifiers   ||   Next topic: -->> Operators in C


📚 Explore More Topics

🗄️ SQL Interview Questions & Answers

SQL SELECT Statement FAQ SQL Restricting & Sorting Data FAQ SQL Group Functions & Aggregated Data FAQ SQL Multiple Tables (JOINs) FAQ SQL Subqueries FAQ SQL DML Statements (Managing Tables) FAQ SQL Indexes, Synonyms & Sequences FAQ SQL DDL (Tables & Relationships) FAQ SQL Views FAQ SQL Indexing Best Practices FAQ SQL Window & Analytic Functions FAQ

🐍 Python Interview Questions & Answers

Python Interview Questions Python Syntax & Variables FAQ Python Data Types FAQ Python If-Else FAQ Python Loops FAQ Python Functions Interview Q Python String Manipulation FAQ Python Lists & Dictionaries FAQ Python Tuples & Sets FAQ Python Exception Handling FAQ Python OOP Interview Questions

☕ Java Interview Questions & Answers

Java Introduction Interview Q Java Development Environment FAQ Java Data Types FAQ Java Control Flow & Operators FAQ Java Basic Input/Output FAQ Java Arrays FAQ Java Strings FAQ Java Methods FAQ Java Basic OOP Concepts FAQ Java Advanced OOP Concepts FAQ Java OOP Best Practices FAQ Java Exception Handling FAQ Java Synchronization FAQ Java Threads & Concurrency FAQ Java Collection Framework FAQ Java File I/O & Serialization FAQ Java Serialization & Deserialization FAQ Java Features FAQ Java Inner & Anonymous Classes FAQ Java Memory Management FAQ Java Packages FAQ Java Wrapper Classes FAQ Java Streams & Lambda FAQ

C Language

  • Home
  • Why C Language
  • History of C Language
  • Applications of C Language
  • Introduction To C
    • What is Program?
    • Structure of C Program
    • Working Of C Program
    • CHARACTER SET
    • VARIABLES AND IDENTIFIERS
    • BUILT-IN DATA TYPES
    • OPERATORS AND EXPRESSIONS
    • CONSTANTS AND LITERALS
    • SIMPLE ASSIGNMENT STATEMENT
    • BASIC INPUT/OUTPUT STATEMENT
    • SIMPLE 'C' PROGRAMS
    • Assignments
  • Operators in C Programming
    • Arithmetic Operators
    • Assignment Operators
    • Increment and Decrement Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Other Operators
    • Assignments
  • Conditional Statements
    • DECISION MAKING WITHIN A PROGRAM
    • CONDITIONS
    • IF STATEMENT
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • SWITCH CASE
    • Assignments
  • Loops Statements
    • Introduction to Loops
    • GO TO Statement
    • Do while Loop
    • While Loop
    • Nested While Loop
    • Difference Between While and Do while
    • Difference Between Goto and loop
    • while loop assignments
    • C FOR Loop
    • C For loop examples
    • Nested for loop
    • Nested for loop examples
    • Infinite while Loops
    • Infinite for Loops
    • Continue in Loops
    • break in Loops
    • difference while do..while & for
    • Assignments
  • Arrays
    • One Dimensional Array
    • Declaring 1D Arrays
    • Initilization of 1D arrays
    • Accessing element of one 1D Array
    • Read and Display 1D Arrays
    • Two Dimensional Arrays
    • Declare 2D Arrays
    • Read and Display 2D Arrays
    • Assignments/Examples
  • Functions
    • Introduction
    • Need For User-Defined Function
    • Multiple Function Program
    • Modular Programming
    • Elements Of User Defined Function
    • Function Definition
    • Function Declaration
    • Types of functions
    • Nesting of Function
    • Recursion
    • Passing Array To Functions
    • Scope,Visibility and Lifetime of Variables
    • Assignments
  • Structure
    • Introduction
    • Array vs Structure
    • Defining Structure
    • Declaring Structure Variables
    • Type Defined Structure
    • Accessing Structure Members
    • Structure Initilization
    • Copying & Comparing Structure Variables
    • Array of Structure
    • Arrays Within Structure
    • Structures Within Structures
    • Structures and Functions
    • Structure Examples/Assignments
  • Union
    • Define Union
    • Create and use Union
    • Difference Between Structure and Union
    • Union Examples
    • Union FAQ
  • Pointers
    • What Are Pointers In C?
    • How Do We Use Pointers In C?
    • Declaration Of A Pointer
    • The Initialization Of A Pointer
    • Syntax Of Pointer Initialization
    • Use Of Pointers In C
    • The Pointer To An Array
    • The Pointer To A Function
    • The Pointer To A Structure
    • Types Of Pointers
    • The Null Pointer
    • The Void Pointer
    • The Wild Pointer
    • The Near Pointer
    • The Huge Pointer
    • The far Pointer
    • dangling pointer
    • Accessing Pointers- Indirectly And Directly
    • Pros Of Using Pointers In C
    • Cons Of Pointers In C
    • Applications Of Pointers In C
    • The & Address Of Operator In C
    • How To Read The Complex Pointers In C?
    • Practice Problems On Pointers
  • File Processing
    • File Handling In C
    • Types Of Files In C
    • Operations Done In File Handling
    • File Examples
    • Binary Files
    • count words,lines in a file
    • Copy files
    • Update File
    • count vowels in a file
  • Preprocessor
    • Macro substitution division
    • File Inclusion
    • Conditional Compilation
    • Other directives
    • Examples
  • Dynamic Memory Allocation
    • malloc
    • calloc
    • free
    • realloc
    • Examples
  • Storage Classes
  • Graphics
  • Frequently Asked Interview Questions (FAQ)
    • Introduction To C FAQ
    • Operators FAQ
    • Conditional Statements FAQ
    • Loops FAQ
    • Arrays FAQ
    • Function FAQ
    • Structure FAQ
    • Pointers FAQ
    • Files FAQ
    • Storage classes FAQ
    • Dynamic Memory FAQ
  • Programs/Assignments
    • Introduction To C
    • Operators
    • Conditional Statements
    • Loops
    • Arrays
    • Function
    • Structure
    • Pointers
    • Files
    • Storage classes
    • Dynamic Memory
  • Case Studies
  • Multiple Choice Questions
    • Introduction To C MCQ
    • Operators MCQ
    • Conditional Statements MCQ
    • Loops MCQ
    • Arrays MCQ
    • Function MCQ
    • Structure MCQ
    • Pointers MCQ
    • Files MCQ
    • Storage classes MCQ
    • Dynamic Memory MCQ
    • More MCQ

Get in touch

  • tech2dsm@gmail.com

© Sankalan Data Tech. All rights reserved.