C

C Programming

Master the fundamentals of C programming with comprehensive tutorials, examples, and hands-on exercises

Data Types in C

Data types specify the type of data that a variable can store. C provides several built-in data types to handle different kinds of data.

Basic Data Types

Data Type Size (bytes) Range Format Specifier
char 1 -128 to 127 %c
int 4 -2,147,483,648 to 2,147,483,647 %d
float 4 3.4E-38 to 3.4E+38 %f
double 8 1.7E-308 to 1.7E+308 %lf

Modified Data Types

You can modify basic data types using type modifiers:

signed & unsigned

Controls whether the variable can hold negative values

short & long

Controls the size of the variable

Data Types Example
#include <stdio.h>

int main() {
    // Basic data types
    char letter = 'A';
    int age = 25;
    float height = 5.9;
    double pi = 3.141592653589793;
    
    // Modified data types
    unsigned int positive_number = 4000000000U;
    long long big_number = 9223372036854775807LL;
    short small_number = 32767;
    
    // Print values
    printf("Character: %c\n", letter);
    printf("Integer: %d\n", age);
    printf("Float: %.2f\n", height);
    printf("Double: %.15lf\n", pi);
    printf("Unsigned int: %u\n", positive_number);
    printf("Long long: %lld\n", big_number);
    printf("Short: %hd\n", small_number);
    
    // Size of data types
    printf("\nSize of data types:\n");
    printf("char: %zu bytes\n", sizeof(char));
    printf("int: %zu bytes\n", sizeof(int));
    printf("float: %zu bytes\n", sizeof(float));
    printf("double: %zu bytes\n", sizeof(double));
    
    return 0;
}
Important Note

The size of data types may vary depending on the system architecture. Use sizeof() operator to get the exact size on your system.

Explanation

  • Basic types: char, int, float, double represent common kinds of data with different sizes and ranges.
  • Modifiers: signed/unsigned, short/long adjust range and storage, impacting memory and overflow behavior.
  • Why it matters: Correct types prevent overflow, precision loss, and undefined behavior when performing operations.
  • Portable code: Use sizeof and format specifiers (%d, %u, %f, %lf) to print values reliably across systems.
Keywords
C data types, signed vs unsigned, short long, sizeof, format specifiers
Quick Tips
  • Match printf/scanf format specifiers with the variable type to avoid undefined behavior.
  • Prefer unsigned for values that cannot be negative (e.g., counts, sizes).
  • Be cautious with integer division; cast to double for precise results when needed.

Frequently Asked Questions

C is a powerful, general-purpose programming language that's been around since the 1970s. It's the foundation for many modern languages and is essential for system programming, embedded systems, and understanding how computers work at a low level. Learning C gives you a solid foundation in programming fundamentals.

No prior programming experience is required! Our C programming tutorial is designed for complete beginners. We start with the basics and gradually progress to more advanced topics. However, having some basic computer literacy and logical thinking skills will be helpful.

You need a C compiler to run C programs. For beginners, we recommend using our online C compiler which requires no installation. For local development, you can use GCC (GNU Compiler Collection) which is available on Windows (via MinGW), macOS (via Xcode), and Linux. IDEs like Code::Blocks, Dev-C++, or Visual Studio Code are also helpful.

The time to learn C depends on your dedication and prior experience. With consistent practice (1-2 hours daily), you can grasp the basics in 2-4 weeks and become proficient in 2-3 months. Mastering advanced concepts like pointers, memory management, and data structures may take 6-12 months of regular practice.

C programming skills open doors to various career paths including system programming, embedded systems development, operating system development, device driver programming, game development, and firmware development. Many companies in automotive, aerospace, telecommunications, and IoT sectors actively seek C programmers.

Absolutely! C remains highly relevant and is consistently ranked among the top programming languages. It's essential for system programming, embedded systems, IoT devices, and performance-critical applications. Many modern languages are built on C, and understanding C helps you become a better programmer overall.