C

C Fundamentals

18 lessons

Progress0%
1. Introduction to C
1What is C?
2. Variables and Data Types
1Data Types in C
3. Control Flow
ConditionalsLoops
4. Functions
Defining FunctionsRecursion
5. Arrays and Pointers
Arrays and StringsPointers
6. Memory Management
Dynamic MemoryStructs and Files
7. Preprocessor & Macros
Preprocessor DirectivesMacros & Inline Functions
8. Bitwise Operations
Bitwise OperatorsBit Flags & Masking
9. Enums, Unions & typedef
Enums & typedefUnions & Complex Types
10. Multi-file Programs
Header Files & Compilation UnitsLinkage, Storage Classes & Make
All Tutorials
CVariables and Data Types
Lesson 2 of 18 min
Chapter 2 · Lesson 1

Data Types in C

C has a small set of basic data types:

Integer Types:

  • char: 1 byte (also used for characters)
  • short: At least 2 bytes
  • int: At least 2 bytes (usually 4)
  • long: At least 4 bytes
  • long long: At least 8 bytes

Floating Point:

  • float: Single precision (4 bytes)
  • double: Double precision (8 bytes)
  • long double: Extended precision

Modifiers:

  • signed: Can hold negative values (default)
  • unsigned: Only positive values

sizeof Operator: Returns the size in bytes of a type or variable.

Type Qualifiers:

  • const: Value cannot be changed
  • volatile: May change unexpectedly (hardware)

Code Examples

C Data Typesc
#include <stdio.h>
#include <limits.h>
#include <float.h>

int main() {
    // Integer types
    char c = 'A';
    short s = 32767;
    int i = 2147483647;
    long l = 2147483647L;
    long long ll = 9223372036854775807LL;
    
    printf("char: %c (ASCII: %d)\n", c, c);
    printf("int: %d\n", i);
    
    // Unsigned types
    unsigned int ui = 4294967295U;
    printf("unsigned int: %u\n", ui);
    
    // Floating point
    float f = 3.14159f;
    double d = 3.141592653589793;
    
    printf("float: %.5f\n", f);
    printf("double: %.15f\n", d);
    
    // sizeof operator
    printf("\nSizes in bytes:\n");
    printf("char: %zu\n", sizeof(char));
    printf("int: %zu\n", sizeof(int));
    printf("long: %zu\n", sizeof(long));
    printf("float: %zu\n", sizeof(float));
    printf("double: %zu\n", sizeof(double));
    
    // Constants
    const double PI = 3.14159265359;
    printf("\nPI: %.11f\n", PI);
    
    // Type limits
    printf("\nInt range: %d to %d\n", INT_MIN, INT_MAX);
    
    return 0;
}

C data type sizes can vary by platform. Always use sizeof() when you need exact sizes. limits.h contains type range constants.

Quick Quiz

1. What's the minimum guaranteed size of an int in C?

Was this lesson helpful?

PreviousNext