C Tutorial — Learn C Programming
Key takeaway: This free C tutorial teaches you systems programming from scratch — variables, pointers, arrays, functions, structs, and memory management — with practical code examples you can compile and run.
C is a general-purpose, procedural programming language created in 1972. It is used for operating systems, embedded systems, game engines, and performance-critical applications. This tutorial is for beginners, CS students, and developers who want to understand how computers work at a low level.
Last updated: September 2026
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
#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,doublerepresent common kinds of data with different sizes and ranges. - Modifiers:
signed/unsigned,short/longadjust 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
sizeofand format specifiers (%d,%u,%f,%lf) to print values reliably across systems.
Keywords
Quick Tips
- Match
printf/scanfformat specifiers with the variable type to avoid undefined behavior. - Prefer
unsignedfor values that cannot be negative (e.g., counts, sizes). - Be cautious with integer division; cast to
doublefor precise results when needed.