📚 College Credit Guide ✓ UPI Study 🕐 10 min read

What Is Pass By Value vs Pass By Reference in C?

This article explains how C passes arguments, why values get copied, and how pointers let a function change the original variable.

US
UPI Study Team Member
📅 July 27, 2026
📖 10 min read
US
About the Author
The UPI Study team works directly with students on credit transfer, degree planning, and course selection. We've helped thousands of students figure out what counts toward their degree and how to finish faster without paying more than they have to. This post is written the way we'd explain it to you directly.
🦉

In C, functions get copies of your arguments by default, not the original variables. That means a function can read the value you send it, but a change inside that function usually stays inside that function. If you want the function to change the caller's variable, you pass an address with a pointer. That is the heart of is pass by value vs pass by reference in c. C does not give you true pass by reference the way some other languages do. It gives you pass by value every time, whether you send an int, a float, or a pointer. The pointer itself still gets copied, but that copied address points to the same memory location as the original variable. Students trip over this in programming in c because the code looks close to what they expect from math or from other languages. A function named updateScore sounds like it should update the score, but it only changes a local copy unless you pass a pointer. That small detail matters in lab work, exam questions, and real code with 2 or 3 inputs. A clean way to think about it: values are copied, addresses are shared through copies of pointers. That sounds tricky at first, but the rule stays simple once you test it with a tiny example and print the result before and after the function call. One good test can save 20 minutes of confusion.

Close-up of colorful programming code displayed on a computer monitor with a dark background — UPI Study

What Does Pass By Value Mean in C?

C passes arguments by value, which means the function gets its own copy of each number, character, or pointer you send into it. If you pass 7 into a function, that function sees 7, but it does not own your original variable.

Here is the part students miss in week 1 of programming in c: changing the parameter inside the function changes only the local copy. If the caller stored 7 in a variable named score, and the function adds 5, the caller still keeps 7 after the function returns. That happens because C copies the value at the moment of the call.

A tiny example makes the rule obvious. If main has int x = 10; and it calls addOne(x), then addOne gets a copy of 10. Inside addOne, x can become 11, but that new 11 lives in the function's own space, not in main's variable. Print both values and you will see two different numbers, not one shared number.

The catch: The function can still read the copied value just fine, so pass by value works well for 1 small int, a char, or a simple flag. It feels boring, but boring code often avoids mistakes.

A lot of beginners expect the caller's variable to change because the function name sounds active. C does not care about the name. It cares about memory. That is why a function can return a new value, or it can take a pointer if it needs to work on the original data.

Why Does C Not Pass By Reference?

C does not have true pass by reference, even though people say that phrase all the time in class notes and forum posts. The language always passes a value, and that rule stays the same in C99, C11, and newer compilers.

The confusion comes from pointers. A pointer holds an address, so when you pass a pointer into a function, the function can reach the original memory location through that address. Students hear that and call it pass by reference, but C still passed a value—the value just happened to be an address. That difference matters in programming in c because it changes how you reason about the call.

Reality check: A pointer argument can act like a reference, but the pointer itself still gets copied. The copied pointer and the original pointer both point to the same place, which is why the function can write to the same int, float, or struct field.

That is also why C feels stricter than languages that offer real references. You have to say exactly what you mean with & and *. I like that honesty. It forces clear thinking, and clear thinking beats magical-looking syntax when your code breaks at 2 a.m.

This also explains why some errors look weird. If you pass a plain int to a function and expect the function to edit the caller's variable, nothing happens. If you pass its address instead, the function reaches the same memory and the edit sticks.

How Do Pointers Let Functions Change Variables?

Pointers let a C function change a caller's variable because the function receives an address, not a fresh copy of the data. That address points to the same memory cell the caller uses, so one write can change the original value. A quick lab test in a Programming in C class shows this fast, and the result usually surprises students the first time.

  1. Start with an int in main, such as int score = 80; and pass its address with &score. The function now knows where score lives instead of seeing only the number 80.
  2. Inside the function, use *ptr to reach the original value and add 5. If the score starts at 80, the function can change it to 85 in one step.
  3. Print the value before and after the call. A simple test like 80 before and 85 after proves the pointer touched the same memory location.
  4. Use this pattern for swap, because swap needs 2 variables at once. If you try swap with plain values, the caller keeps the original 2 numbers unchanged.
  5. Use it again for an increment helper that handles a threshold, such as raising a quiz score only if it stays below 100. The function can stop at 100 and leave the caller with the updated number.
  6. Remember that the pointer itself still copied by value. That copied address gives the function access to the original data, which is why the change survives after the function returns.

What this means: Pointer-based argument passing feels a little strange at first, but it gives you direct control over memory without returning a dozen values from one function.

Programming In C UPI Study Course

Learn Programming In C Online for College Credit

This is one topic inside the full Programming In C course on UPI Study — a self-paced, online class that earns real college credit. Credits are ACE and NCCRS evaluated and transfer to partner colleges across the US and Canada. Courses start at $250 with no deadlines and lifetime access.

See Programming In C Course →

Which C Function Arguments Should Stay Copies?

Pass by value works best when you want a function to stay hands-off. A small int, a grade like 92, or a single char travels cleanly as a copy, and that keeps the code easier to follow in a 50-minute lab.

Worth knowing: A function that only reads its inputs often becomes easier to test, while pointer-heavy code can hide mistakes if you rush through it.

How Do Real C Examples Show the Difference?

A student in a 12-week Programming in C course at Santa Monica College might write a lab function to raise quiz scores from 78 to 88, then print both the original and the changed value. That one test shows the whole idea fast: a plain int argument stays a copy, but a pointer argument reaches the original memory. Students who study online for transferable credit or ace NCCRS credit often run into this exact lab pattern, because instructors love short functions that expose whether a variable changed in main or stayed local. The same lesson shows up in a score update, a swap exercise, or a function that adds 10 points only if the score stays below 100.

Bottom line: The best student habit is printing values before and after every test call, because a 2-line check catches confusion faster than a long guess.

Where UPI Study Fits

90+ college-level courses give students a lot of room to build credit around a single topic like C pointers, and that matters when a school limits transfer work to 90 semester hours. UPI Study offers all courses with ACE and NCCRS approval, so the credit review process stays tied to the same two bodies many colleges already use for non-traditional credit.

UPI Study charges $250 per course or $99 per month for unlimited access, and that pricing helps when someone wants to study online without locking into a full semester schedule. Fully self-paced study also fits a student who needs 2 weeks for one unit and 2 days for the next.

The Programming in C course fits this exact topic because pointer rules and function arguments show up early in the material, not as a tiny side note. UPI Study works well for students who want ACE NCCRS credit from a course that matches a real college subject, and the partner college setup gives the credit a clear path toward transfer at cooperating schools in the US and Canada.

I like this kind of setup for students who want structure without a fixed clock. It cuts the wait time that usually comes with a 15-week term, and it gives room to finish faster when the material clicks.

What Should Students Remember Before Writing C Functions?

C passes values, not magic. That sentence saves more time than any fancy diagram, because it tells you to ask one question every time: did I send the data itself, or did I send an address?

If you want a function to read a value, pass a copy. If you want it to change the caller's variable, pass a pointer and use dereferencing with care. That choice shows up in every serious programming in c assignment, from a tiny increment helper to a swap routine with 2 addresses.

Students often make the same mistake twice. They write the function, test once, and assume the result should update the original variable. Then they spend 20 minutes blaming the compiler. The compiler did its job. The argument type was the real issue.

A good habit helps here: write the function header, circle each parameter, and mark whether it should stay private or reach the caller's memory. That tiny check catches more bugs than memorizing slogans about by pass by vs pass by reference.

Your next step is simple. Pick one short C function, test it with 2 prints, then change one argument to a pointer and watch how the behavior changes.

Frequently Asked Questions about C Argument Passing

Final Thoughts on C Argument Passing

The clean rule in C never changes: functions get copies unless you pass an address. That means pass by value handles most small jobs, while pointers handle the jobs that need to touch the original data. If you remember only one thing, remember this split, because it explains almost every surprise students hit in early labs. A lot of confusion comes from language, not code. People say pass by reference, but C still passes values, even when the value happens to be a pointer. Once you see that, the weird parts stop feeling weird. A function that changes a caller's variable does not break the rule; it just uses an address to reach the same memory. That idea shows up in swap functions, score updates, and simple input checks. It also shows up in exams, where one small symbol like & can change the whole answer. C rewards careful reading and plain habits. That is annoying on a bad day, and very useful on a good one. Before you move on, write one function that takes an int by value and one that takes an int by pointer. Print both results. That 2-test habit will make the difference stick faster than reading another page of notes.

How UPI Study credits actually work

Ready to Earn College Credit?

ACE & NCCRS approved · Self-paced · Transfer to colleges · $250/course or $99/month

More on Programming In C
© UPI Study. This article and its educational content are solely owned by UPI Study and licensed under CC BY-NC-ND 4.0. It is not free to reuse or modify. Any citation must credit UPI Study with a direct link to this page.