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
Function Types in C
C functions can be categorized based on their return types and parameters. Understanding different function types helps in writing more organized and efficient code.
1. Functions with No Parameters and No Return Value
#include <stdio.h>
void greet(void) {
printf("Hello, World!\n");
printf("Welcome to C Programming\n");
}
int main() {
greet(); // Function call
return 0;
}2. Functions with Parameters but No Return Value
#include <stdio.h>
void printSum(int a, int b) {
int sum = a + b;
printf("Sum of %d and %d is: %d\n", a, b, sum);
}
void displayInfo(char name[], int age) {
printf("Name: %s\n", name);
printf("Age: %d\n", age);
}
int main() {
printSum(10, 20);
displayInfo("Alice", 25);
return 0;
}3. Functions with No Parameters but Return Value
#include <stdio.h>
int getRandomNumber(void) {
return 42; // Simple example
}
float getPi(void) {
return 3.14159;
}
int main() {
int num = getRandomNumber();
float pi = getPi();
printf("Random number: %d\n", num);
printf("Value of Pi: %.5f\n", pi);
return 0;
}4. Functions with Parameters and Return Value
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
float calculateArea(float length, float width) {
return length * width;
}
int findMax(int arr[], int size) {
int max = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
int main() {
int result = add(15, 25);
printf("Addition result: %d\n", result);
float area = calculateArea(5.5, 3.2);
printf("Area: %.2f\n", area);
int numbers[] = {10, 45, 23, 67, 12};
int maxNum = findMax(numbers, 5);
printf("Maximum number: %d\n", maxNum);
return 0;
}Key Points:
- void functions don't return any value
- Functions can accept multiple parameters of different types
- Return type must match the type of value being returned
- Function prototypes should be declared before use