Skip to main content
Advertisement

C: Functions

A core feature that allows you to bundle code into reusable units for better management.

1. Function Definition and Invocation

#include <stdio.h>

// Function definition
int add(int a, int b) {
return a + b;
}

int main() {
int sum = add(10, 20); // Function call
printf("Total sum: %d\n", sum);
return 0;
}

2. Parameters and Return Values

  • Parameter: Input values passed into the function.
  • Return Value: The result the function sends back after execution.
  • void type: Used when a function does not return a value (e.g., void printHello()).

tip

When writing large programs, breaking down features into smaller functions makes debugging and maintenance much easier.

Advertisement