CSSE 132 · Fall 2026–2027 · Coding review
CSSE132 Coding Final: Review and Practice
Build confidence one small function at a time. Review the examples, then try five independent exercises on your course VM. Allow about 10 minutes for the guide and 45–60 minutes for practice.
1. What to expect
The coding final is worth 40 points and focuses on practical C programming: arrays, loops, pointers, strings, structs, and dynamic memory. You will write and test small functions. Sockets and ARM64 assembly coding are excluded from this coding portion.
Practice compiling, testing, and debugging on the course Linux VM. Start with a function you understand, get it compiling, and test a small example before moving on. This practice set teaches transferable skills; its functions and tests are not the exam questions.
2. Essential skills
For more help, revisit pointers and arrays, output pointers, strings and structs, and heap memory. Lab 5 and Homework 5–7 provide useful C practice.
A. Arrays and loops
Pass an array with its length. Inside a function, the array parameter gives access to elements; it does not remember how many there are.
| C code | What this does |
|---|---|
| Visit valid elements. Start with zero. The condition i < len visits indices 0 through len − 1. const means this function does not write through a. |
Common mistake: Using i <= len reads one element too far. sizeof(a) inside this function measures a pointer, not the original array.
Debugging tip: For a three-element input, write down i = 0, 1, 2 and track result after each step.
B. Pointers and caller-visible changes
A pointer holds an address. &x obtains the address of x; *p accesses the object at the address stored in p. NULL represents no object and must not be dereferenced.
| C code | What this does |
|---|---|
| Follow the address. The caller passes &score. The parameter p is a copy of that address, but *p refers to the same score object. |
Common mistake: Assigning a different address to p changes only the local pointer. It does not change the caller’s integer.
Debugging tip: In GDB, compare print p (address) with print *p (pointed-to value). Check the address is valid before dereferencing.
C. Strings and the terminator
A C string is a character sequence ending at the first null character, \0. The terminator occupies one byte and is different from the digit '0'.
| C code | What this does |
|---|---|
| Keep the ending byte. The writable array contains c, a, p, and a zero byte. Traversal stops before reading beyond the terminator. A string literal should not be modified through a char pointer. |
Common mistake: Allocating strlen(text) bytes leaves no space for the terminator. memcpy copies a byte count; it does not add a terminator for you.
Debugging tip: Use print word and print word[3] in GDB. For copied text, check both the capacity and the location of \0.
D. Struct fields
A struct groups fields. Use . with a struct object and -> with a pointer to a struct. Passing its address lets a helper update the original.
| C code | What this does |
|---|---|
| Choose the operator by type. gauge is a struct; &gauge is a pointer. The helper receives that pointer and writes the level field in the original object. |
Common mistake: Using m.level when m is a pointer, or updating a local struct copy and expecting the original to change.
Debugging tip: Ask “object or pointer?” first. Inspect print *m or print m->level at a breakpoint.
E. Dynamic memory and ownership
malloc requests bytes and returns a pointer or NULL. Heap storage lasts until free. Its contents must be initialized before use; a returned heap pointer can remain valid after a function returns.
| C code | What this does |
|---|---|
| Count elements and bytes. sizeof *pair is the size of one integer. Allocate two integers, check success, initialize them, then free the starting address once. Include <stdlib.h> for malloc and free. |
Common mistake: Allocating sizeof(pointer) instead of enough element bytes; returning the address of a local variable; using a block after free.
Debugging tip: Write down the element count, requested bytes, and which code owns the free. If allocation fails, stop before accessing the block.
3. Five mini coding exercises
Complete the TODOs in practice.c.
1. Compare neighboring readings (7–10 minutes)
int countDrops(const int *readings, int len);Count positions whose value is lower than the immediately preceding value. Do not change the array. len is nonnegative; lengths 0 and 1 give 0.
Examples: {8, 5, 5, 2} → 2; {1, 3} → 0.
TODO: Replace this function’s placeholder body in practice.c. Run ./test_practice arrays after rebuilding.
Small local check
int a[] = {8, 5, 5, 2};
assert(countDrops(a, 4) == 2);The checks use assert from <assert.h>; they are already included in the supplied test program.
2. Update an even integer (5–7 minutes)
int halveEven(int *value);If the pointed-to integer is even, divide it by two and return 1. Otherwise leave it unchanged and return 0. Include negative integers and zero.
Examples: 14 becomes 7, returning 1; 9 stays 9, returning 0.
TODO: Replace this function’s placeholder body in practice.c. Run ./test_practice pointers after rebuilding.
Small local check
int n = 14;
assert(halveEven(&n) == 1);
assert(n == 7);The checks use assert from <assert.h>; they are already included in the supplied test program.
3. Count punctuation (7–10 minutes)
int countMarks(const char *text);Count periods and exclamation marks in a null-terminated string. Do not change the text. An empty string gives 0.
Examples: "Hi! Wait..." → 4; "why?" → 0.
TODO: Replace this function’s placeholder body in practice.c. Run ./test_practice strings after rebuilding.
Small local check
assert(countMarks("Hi! Wait...") == 4);The checks use assert from <assert.h>; they are already included in the supplied test program.
4. Record one sale (7–10 minutes)
int sellOne(struct stock *item);The provided struct stock has integer fields available and sold. If available is positive, decrease it by one, increase sold by one, and return 1. Otherwise change neither field and return 0. Both fields begin nonnegative; updates fit in int.
Examples: {3, 2} becomes {2, 3}; {0, 4} stays {0, 4}.
TODO: Replace this function’s placeholder body in practice.c. Run ./test_practice structs after rebuilding.
Small local check
struct stock item = {3, 2};
assert(sellOne(&item) == 1);
assert(item.available == 2 && item.sold == 3);The checks use assert from <assert.h>; they are already included in the supplied test program.
5. Allocate a ramp (9–12 minutes)
int *makeRamp(int len, int start);Allocate len integers and initialize element i to start + i. Assume 1 ≤ len ≤ 1000 and every sum fits in int. Return NULL on allocation failure. The caller owns the result and must free it once.
Examples: (3, 4) produces {4, 5, 6}; (1, −2) produces {−2}.
TODO: Replace this function’s placeholder body in practice.c. Run ./test_practice heap after rebuilding.
Small local check
int *p = makeRamp(3, 4);
assert(p != NULL && p[2] == 6);
free(p);The checks use assert from <assert.h>; they are already included in the supplied test program.
4. Get the practice files
Use the practice folder in your course repository on the VM. Save your editor files and go to the top of your course repository (the directory containing your homework and lab folders), then run:
git status
git pull --no-rebase --ff-only
cd coding-final-practice
make
make test
If Git reports an error, stop and ask your instructor. Do not discard or reset unfinished work. You do not need to copy files or download a ZIP for this route.
Optional: download a separate practice copy
Download the coding practice ZIP (starter, header, tests, Makefile, and README). Use a separate directory to keep earlier attempts.
On the course VM, in a directory outside your existing practice folder:
wget https://www.rose-hulman.edu/class/csse/csse132/2627a/materials/coding-final-practice.zip
unzip coding-final-practice.zip
cd coding-final-practice
make
make testIf you prefer individual files: README, practice.c, practice.h, test_practice.c, and Makefile.
The starter builds but intentionally fails the tests until you complete the TODOs. Here, make builds; make test runs every exercise group. A failing group does not stop the remaining groups. A compilation error must be fixed first. These local tests are examples, not a complete correctness guarantee. The practice does not require a Gradescope submission.
5. Approaches and feedback
Before coding, write one input and expected output. Decide what changes in the caller and what is returned. For a loop, identify its first and last valid indices. For an allocation, count bytes and identify who frees the result.
Complete practice solutions are being held for instructor-led review. Bring a small failing example and explain what you expected. Use the checks below for immediate feedback without giving away the exercise implementations.
- What does changing p itself do differently from changing *p?
- How many bytes does the string "sun" need?
- If struct meter *m points to a valid meter, how do you read its level?
- Can a function safely return a pointer to an automatic local array?
Self-check answers
- Changing p replaces the local address. Changing *p writes to the object it points to.
- Four: three letters plus the null terminator.
- m->level, equivalently (*m).level.
- No. Its lifetime ends when the function returns. Use caller-provided storage or correctly owned heap storage.
6. Debugging quick reference
Fix the first compiler error before chasing later messages. Compiler errors prevent an executable from being built; a runtime failure happens after execution starts. A failed assertion means a test’s expected condition was false.
make # build; read warnings too
make test # run all practice groups
./test_practice arrays # run one group
gdb --args ./test_practice arrays
# In GDB: run, bt, list, print len, print readings[0], next, quit
# Equivalent direct build:
gcc -std=c99 -Wall -Wextra -g -O0 practice.c test_practice.c -o test_practice
- Segmentation fault: use bt to locate your function. Check pointer initialization, NULL, and whether the object is still alive.
- Wrong pointer update: distinguish an address from the pointed-to value. Inspect both.
- Uninitialized result: give accumulators a starting value before reading or adding to them.
- String trouble: find the first \0 and check capacity includes that byte.
- Wrong array result: trace the smallest failing input, checking index bounds and whether the input was accidentally changed.
- Heap trouble: allocate element count times element size, check success, and free each original heap address exactly once after use.
7. Exam preparation checklist
- I can write and test a function that traverses an array.
- I can explain what a pointer points to and update a value through it.
- I can find a string’s terminator and stay within its storage.
- I can access and modify struct fields using . and ->.
- I can allocate, initialize, use, and free heap memory.
- I can compile, test, and debug on the course VM without assistance.
- I have checked the instructor’s final timing, resource, and submission instructions.