Lab P3 β€” Implement call by value, call by address, and call by reference.

NBC351 Β· Program 3⏱ 8 min read❓ 5 MCQs

Aim

Aim: Demonstrate call by value, address, and reference.

Theory

Demonstrate call by value, address, and reference.

C++ Program

#include 
using namespace std;
void byValue(int a){ a=100; }
void byAddress(int* a){ *a=100; }
void byRef(int& a){ a=100; }
int main(){
    int x=10; byValue(x); cout<<"after value: "<

Expected Output

after value: 10
after address: 100
after ref: 100

Explanation

  • byValue doesn't change original.
  • byAddress changes via pointer.
  • byRef changes via reference.

Viva / Important Questions

Short Questions

  1. Define call by value/address/reference.
  2. When use each?

Long Questions

  1. Explain the program in detail.
  2. Discuss key concepts demonstrated.

MCQ Practice

1. Call by value passes:

  • Copy
  • Address
  • Reference
  • Nothing
Answer: Copy.

2. Call by address uses:

  • Pointer
  • Reference
  • Copy
  • None
Answer: Pointer.

3. Call by reference uses:

  • Alias
  • Copy
  • Pointer
  • None
Answer: Alias.

4. Which can modify original? (value)

  • No
  • Yes
  • Maybe
  • Always
Answer: No.

5. Reference must be:

  • Initialized
  • Optional
  • Null
  • None
Answer: Initialized.

Quick Revision

  • Value: copy (no change).
  • Address/Ref: modify original.