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
Functions in C
Functions are reusable blocks of code that perform specific tasks. They help organize code, reduce repetition, and make programs more modular and easier to maintain.
Function Syntax
return_type function_name(parameter_list) {
// function body
return value; // if return_type is not void
}Simple Function Example
#include <stdio.h>
// Function declaration
void greet();
int add(int a, int b);
int main() {
greet();
int result = add(5, 3);
printf("5 + 3 = %d\n", result);
return 0;
}
// Function definition
void greet() {
printf("Hello, World!\n");
}
int add(int a, int b) {
return a + b;
}Function with Parameters
#include <stdio.h>
// Function declarations
float add(float a, float b);
float subtract(float a, float b);
float multiply(float a, float b);
float divide(float a, float b);
int main() {
float num1, num2;
char operator;
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter second number: ");
scanf("%f", &num2);
switch (operator) {
case '+':
printf("Result: %.2f\n", add(num1, num2));
break;
case '-':
printf("Result: %.2f\n", subtract(num1, num2));
break;
case '*':
printf("Result: %.2f\n", multiply(num1, num2));
break;
case '/':
printf("Result: %.2f\n", divide(num1, num2));
break;
default:
printf("Invalid operator!\n");
}
return 0;
}
float add(float a, float b) {
return a + b;
}
float subtract(float a, float b) {
return a - b;
}
float multiply(float a, float b) {
return a * b;
}
float divide(float a, float b) {
if (b != 0) {
return a / b;
} else {
printf("Error: Division by zero!\n");
return 0;
}
}Function Benefits
Reusability
Write once, use multiple times
Modularity
Break complex problems into smaller parts
Easier Debugging
Isolate and fix issues more easily
Readability
Make code more organized and understandable