FirstHack 2026 — a 36-hour online hackathon built for first-year students.•₹1,00,000 prize pool•22 Oct – 4 Nov•Open to every branch and every stream•Certificate for every team that submits•3 rounds•FirstHack 2026 — a 36-hour online hackathon built for first-year students.•₹1,00,000 prize pool•22 Oct – 4 Nov•Open to every branch and every stream•Certificate for every team that submits•3 rounds•
Simulating pass-by-reference in C, returning multiple values, and modifying pointers themselves.
11 min read·Lesson 4 of 6·Pro
C has only pass-by-value
There is no pass-by-reference in C. Every argument is copied. What people call "pass by reference in C" is really "pass a copy of an address" — and because the copy of the address still points at the original, the function can reach it.
Hold that sentence. It explains everything below.
C
#include <stdio.h>
void broken(int x) { x = 99; }
void works(int *x) { *x = 99; }
int main(void)
{
int a = 1, b = 1;
broken(a);
works(&b);
printf("a = %d, b = %d\n", a, b); /* a = 1, b = 99 */
return 0;
}
The rest of this lesson is Pro
The free lessons of Pointers and Memory in C finish what
they start — read those first if you have not. This one goes further, and it
is part of the paid half.
A pass opens the paid lessons of every course, the mock test papers
and the company-wise series. It ends on its own date; nothing renews by itself.