Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions experiment/procedure.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
**Call By Value**
This simulation has two modules:

1. Press Start to start the experiment.
2. Press Next to see the execution of the code.
3. Relavant line in the code is shown here.
4. The output of the code is shown in the right.
1. Call By Value
2. Call By Reference

**Call By Reference**
Open the simulation page and click the thumbnail of the module you want to run.

1. Press Start to start the experiment.
2. Press Next to see the execution of the code.
3. Relavant line in the code is shown here.
4. The output of the code is shown in the right.
#### Steps for Call By Value

#### Procedure
1. Click **Start** to begin execution.
2. Observe the first highlighted code line in the Program Code panel.
3. Click **Next** to move to the next execution step.
4. At each step, observe all three panels together:
- **Program Code**: currently executing line is highlighted.
- **Memory Map**: addresses and stored byte values are updated.
- **Code Output / Explanation**: printed output and reasoning for that step.
5. Continue clicking **Next** to trace declaration of `A`, declaration of pointer `P`, assignment `P = &A`, dereferencing `*P`, and update of `A` through pointer.
6. Use **Back** to revisit previous steps and verify how values and addresses change in reverse order.
7. Continue until program execution completes; the simulation resets to initial state for a fresh run.

In this lab you will learn the basic concepts of pointers and addresses. You will also understand the process of memory allocation and passing in reference.
#### Steps for Call By Reference

1. Click **Start** to begin execution.
2. Click **Next** to step through `main()` and the function call to `swap(&A, &B)`.
3. Observe pointer variables in the swap function (`Pa`, `Pb`) and the temporary variable (`temp`) in the **Memory Map**.
4. Track how dereferencing updates original values:
- `temp = *Pa`
- `*Pa = *Pb`
- `*Pb = temp`
5. Compare **Code Output** before and after swap to confirm that values of `A` and `B` are exchanged in caller memory.
6. Use **Back** to inspect reverse flow and confirm each intermediate memory state.
7. Run till completion to see final swapped values and automatic reset.

#### What to Verify During Simulation

1. Every variable occupies a memory address.
2. A pointer stores an address, and dereferencing accesses/modifies value at that address.
3. Passing addresses to a function allows modification of original variables (call by reference behavior).

**Note for Mobile Users:**

This simulation is optimized for desktop computers with larger screens and mouse interaction. If you access this experiment on a mobile device, please rotate your device to **landscape mode** for the best experience. Some features may be limited or harder to use on small screens.
7 changes: 5 additions & 2 deletions experiment/references.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
1. [C pointers](http://www.exforsys.com/tutorials/c-language/c-pointers.html)
2. [Pointer](http://en.wikipedia.org/wiki/Pointer_%28computer_science%29)
1. [Pointers in C - GeeksforGeeks](https://www.geeksforgeeks.org/c/pointers-in-c-and-c-set-1-introduction-arithmetic-and-array/)
2. [cppreference - Pointers (C language)](https://en.cppreference.com/w/c/language/pointer)
3. [cppreference - Dynamic Memory Management (malloc, calloc, realloc, free)](https://en.cppreference.com/w/c/memory)
4. [The C Programming Language (2nd Edition) - Kernighan and Ritchie](https://en.wikipedia.org/wiki/The_C_Programming_Language)
5. [Pointer (Computer Programming) - Wikipedia](<https://en.wikipedia.org/wiki/Pointer_(computer_programming)>)
Loading
Loading