Pointers
This simulation has two modules:
- Call By Value
- Call By Reference
Open the simulation page and click the thumbnail of the module you want to run.
Steps for Call By Value
- Click Start to begin execution.
- Observe the first highlighted code line in the Program Code panel.
- Click Next to move to the next execution step.
- 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.
- Continue clicking Next to trace declaration of
A, declaration of pointerP, assignmentP = &A, dereferencing*P, and update ofAthrough pointer. - Use Back to revisit previous steps and verify how values and addresses change in reverse order.
- Continue until program execution completes; the simulation resets to initial state for a fresh run.
Steps for Call By Reference
- Click Start to begin execution.
- Click Next to step through
main()and the function call toswap(&A, &B). - Observe pointer variables in the swap function (
Pa,Pb) and the temporary variable (temp) in the Memory Map. - Track how dereferencing updates original values:
temp = *Pa*Pa = *Pb*Pb = temp
- Compare Code Output before and after swap to confirm that values of
AandBare exchanged in caller memory. - Use Back to inspect reverse flow and confirm each intermediate memory state.
- Run till completion to see final swapped values and automatic reset.
What to Verify During Simulation
- Every variable occupies a memory address.
- A pointer stores an address, and dereferencing accesses/modifies value at that address.
- 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.