100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Data Types in C

Master C data types — int, float, char, double, and modifiers — with sizes, ranges, format specifiers, and examples.

Basics & Data TypesBeginner9 min readJul 7, 2026
Analogies

1. Introduction

A data type in C specifies the kind of value a variable can hold, how much memory it occupies, and what operations can be performed on it. C provides a small set of built-in (primitive) data types along with type modifiers that let programmers fine-tune size and range.

🏏

Cricket analogy: Declaring a player's role as 'bowler' vs 'batsman' determines what actions (bowling figures vs batting average) get tracked and how much scorecard space is reserved — just like a C data type determines memory size and allowed operations.

Choosing the correct data type affects memory usage, precision, and correctness of arithmetic, which is why data types form the foundation for nearly every other C topic, from arrays to structures.

🏏

Cricket analogy: Recording a batsman's strike rate as an int truncates decimals like 133.33 down to 133, just as choosing the wrong data type in C silently loses precision that matters for later analysis.

2. Syntax

c
int variableName;
float variableName;
double variableName;
char variableName;
short int / long int / long long int
unsigned int / signed int

3. Explanation

C's fundamental data types fall into a few categories: integer types (char, short, int, long, long long — each available in signed and unsigned form), floating-point types (float, double, long double) for real numbers with fractional parts, and void, which represents 'no value' and is used for functions that return nothing or generic pointers.

🏏

Cricket analogy: A scorecard uses whole-number types (int) for runs and wickets, but a decimal type (double) for the required run rate like 8.45, and a 'void' placeholder for an abandoned match with no result at all.

Type modifiers — signed, unsigned, short, and long — adjust the size and range of a base type. On a typical 32-bit/64-bit system (LP64), int is commonly 4 bytes (range approximately -2,147,483,648 to 2,147,483,647), char is 1 byte, float is 4 bytes, and double is 8 bytes, though exact sizes are implementation-defined and should be verified with sizeof(). The correct printf/scanf format specifier must match the type: %d for int, %f for float, %lf for double (in scanf), %c for char, and %ld for long.

🏏

Cricket analogy: A 'signed' run tally can go negative (like a bowler's economy differential of -2), while an 'unsigned' wicket count never goes below zero — and using %d to print a long total like a season's aggregate runs (over 2 billion in T20 leagues) would truncate, just as mismatching format specifiers corrupts output.

Common mistake: using %f to scanf a double variable. printf treats float and double the same due to default argument promotion, but scanf requires %lf for double and %f for float — mismatching these causes undefined behavior.

4. Example

c
#include <stdio.h>

int main(void) {
    int i = 42;
    float f = 3.14f;
    double d = 3.14159265358979;
    char c = 'Z';
    unsigned int u = 4000000000u;

    printf("int: %d, size = %zu bytes\n", i, sizeof(i));
    printf("float: %.2f, size = %zu bytes\n", f, sizeof(f));
    printf("double: %.5f, size = %zu bytes\n", d, sizeof(d));
    printf("char: %c, size = %zu bytes\n", c, sizeof(c));
    printf("unsigned int: %u, size = %zu bytes\n", u, sizeof(u));

    return 0;
}

5. Output

text
int: 42, size = 4 bytes
float: 3.14, size = 4 bytes
double: 3.14159, size = 8 bytes
char: Z, size = 1 bytes
unsigned int: 4000000000, size = 4 bytes

6. Key Takeaways

  • C's basic types are int, float, double, char, and void.
  • Modifiers signed/unsigned/short/long adjust size and range of base types.
  • Exact type sizes are compiler/platform-defined; always confirm with sizeof().
  • Use matching format specifiers: %d (int), %f (float print), %lf (double scanf), %c (char).
  • unsigned types can never hold negative values and wrap around on underflow/overflow.
  • double offers roughly twice the precision of float and is preferred for scientific calculations.

Practice what you learned

Was this page helpful?

Topics covered

#CProgrammingStudyNotes#Programming#DataTypesInC#Data#Types#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep