Chapter 4 Functions
Chapter 4 Functions
A function is a block of code designed to perform a specific task. It can be reused in the program to avoid r
Example:
#include <stdio.h>
void greet() {
printf("Hello, World!\n");
int main() {
greet();
return 0;
Function declaration specifies the name, return type, and parameters of a function, enabling the compiler to
Example:
int main() {
return 0;
return a + b;
}
When passing by value, a copy of the argument's value is passed to the function. Changes made to the pa
Example:
#include <stdio.h>
void modify(int x) {
x = x + 10;
int main() {
int a = 5;
modify(a);
return 0;
When passing by reference, the address of the argument is passed, allowing the function to modify the orig
Example:
#include <stdio.h>
*x = *x + 10;
int main() {
int a = 5;
modify(&a);
return 0;