Curriculum
Course: Complete C Programming Course
Login
Text lesson

Working with Data Types in C

In this lesson, you will learn

  • Data Types in C Language

 

Data Types in C

Data types define the type of data a variable can hold.

It helps the compiler to understand how much memory to allocate and how to interpret the stored data. 

 

1. Primary/Basic Data Types

TypeSize (Bytes)*DescriptionExample
int2 or 4Stores integersint a = 10;
float4Stores decimal numbers (single precision)float b = 3.14;
double8Stores decimal numbers (double precision)double d = 3.14159;
char1Stores a single characterchar ch = 'A';

 

2. Derived Data Types

TypeDescriptionExample
ArrayCollection of elements of same data typeint arr[5];
PointerStores memory address of another variableint *p = &a;
FunctionA block of code performing a taskint sum(int x, int y)

 

3. User-Defined Data Types

TypeDescriptionExample
structCollection of variables of different typesstruct Student {int id; char name[20];}
unionSimilar to struct, but shared memoryunion Data {int i; float f;}
enumSet of named integer constantsenum days {SUN, MON, TUE};
typedefRename existing data typetypedef int marks;

 

Additional Type Modifiers

To further control the range and memory of variables, C provides modifiers:

ModifierUsed WithEffect
shortintReduces size
longint, doubleIncreases size
signedint, charAllows negative and positive
unsignedint, charAllows only positive

Example:

short int s;       // Smaller range
long int l;        // Larger range
unsigned int u;    // Only positive integers

 

Summary Table: Primary Data Types in C with Modifiers

Data TypeSize (Bytes)Range (Approx.)Description
char1–128 to 127Stores single character (signed by default)
signed char1–128 to 127Explicitly signed character
unsigned char10 to 255Only positive characters
int4–2,147,483,648 to 2,147,483,647Default integer
signed int4–2,147,483,648 to 2,147,483,647Same as int
unsigned int40 to 4,294,967,295No negative integers
short int2–32,768 to 32,767Short integer
unsigned short int20 to 65,535Positive short integer
long int4 or 8–2,147,483,648 to 2,147,483,647 or moreLarger integer
unsigned long int4 or 80 to 4,294,967,295 or morePositive long integer
long long int8–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807Very large integers
unsigned long long int80 to 18,446,744,073,709,551,615Very large positive integers
float4±3.4 × 10^–38 to ±3.4 × 10^38Single precision real number
double8±1.7 × 10^–308 to ±1.7 × 10^308Double precision real number
long double10 or 12±1.1 × 10^–4932 to ±1.1 × 10^4932Extended precision real number
 

Notes:

  • char is typically signed by default but may vary based on compiler.

  • Use unsigned when negative numbers are not needed — allows larger positive values.

  • Use long and long long when handling large integer values.

  • float, double, and long double are for decimal values, use double if more precision is needed.

 

Example Code Using Various Data Types:

#include<stdio.h>
int main() {
    int age = 25;
    float pi = 3.14;
    char grade = 'A';
    double bigNumber = 123456.789;
    
    printf("Age: %d\n", age);
    printf("Pi: %.2f\n", pi);
    printf("Grade: %c\n", grade);
    printf("Big Number: %.3lf\n", bigNumber);
    return 0;
}

Output

 

 


 

End of the lesson….enjoy learning

 

 

Student Ratings and Reviews

 

 

 

There are no reviews yet. Be the first one to write one.

 

 

Submit a Review