C Programming Tutorial 0/65 lessons ~6 min read Lesson 18
Parameter Passing Techniques
Arguments are copied by default.
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Arguments are copied by default. Pass addresses when the callee must mutate data owned by the caller.
Understanding the topic
Pass by value Copy of value — original unchanged.
Pass by pointer Address passed — callee can modify original.
- Pass by value — Copy of value — original unchanged.
- Pass by pointer — Address passed — callee can modify original.
Step-by-step explanation
- Pass by value — Copy of value — original unchanged.
- Pass by pointer — Address passed — callee can modify original.
Informative example
Example program:
c
#include <stdio.h>void swap(int *a, int *b) {int t = *a; *a = *b; *b = t;}int main(void) {int x = 1, y = 2;swap(&x, &y);printf("%d %d\n", x, y);return 0;}
Output
2 1
Execution workflow
1Parameter Passing Techniques — step by step
1 / 2Pass by value
Copy of value — original unchanged.
Best practices
- Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
- Give every variable a defined value before it is read.
- Stay inside array bounds — C will not stop you from over-running a buffer.
Common mistakes
- Reading uninitialized storage — behavior is undefined.
- Dismissing compiler warnings instead of fixing root causes.
- Ignoring NULL returns from malloc, fopen, and similar APIs.
Hands-on exercise
Practice problems:
- Swap two numbers with pointers
- Modify array element in function
Summary
Parameter Passing Techniques in C — By-value copies versus by-address updates.
Ready to mark this lesson complete?Track your journey across the entire course.