Program Design — Lab 4
Deadline: April 16th, 2026 at 3:00 p.m.
A. Function Overloading and Name Mangling
Use g++ to compile the following program, and then use nm to list the symbols
of the executable file.
double average(double * n1, double& n2)
{
return ((*n1 + n2) / 2.0);
}
int average(int n1, float n2)
{
return ((n1 + n2) / 2);
}
int average(int n1, int n2, int n3)
{
return ((n1 + n2 + n3) / 3);
}
int main() { return 0; }
Answer the following questions in your README:
1. What are the encoded identifiers (mangled names) shown by nm for the
three average functions?
2. Why does the compiler encode function names this way? How does name
mangling support function overloading?
B. Pass-by-value vs. Pass-by-reference
What is the output of the following program? Explain why x and y produce
different results.
#include <iostream>
using namespace std;
Program Design — Lab 4 1
void func(int a, int& b)
{
a = 10;
b = 20;
}
int main()
{
int x = 1, y = 1;
func(x, y);
cout << x << " " << y << endl;
return 0;
}
Answer the following questions in your README:
1. What is the output?
2. Why does x retain its original value while y changes?
C. Default Arguments
Consider the following two function declarations. Which one compiles
successfully, and which one results in a compilation error? Explain the reason.
// Version A
int volume(int l=1, int w=1, int h=1);
// Version B
int volume(int l=1, int w, int h=1);
Answer the following questions in your README:
1. Which version compiles successfully?
2. What is the compilation error in the other version, and why does it occur?
Hand-in Rules
Program Design — Lab 4 2
File Hierarchy
<StudentID>.zip
└── lab4/
└── README
Example for a student with ID E14123456 :
[Link]
└── lab4/
└── README
README
Your README should contain your answers to all three questions (A, B, and C).
Organize your answers clearly with headings for each part.
Submission Rules
1. Name your zip file <StudentID>.zip and place all files under lab4/ .
2. Upload the zip file to Moodle before the deadline (April 16th, 2026 at 3:00
p.m.).
3. Do not include executable files or object files ( .o , .out , .exe ).
Program Design — Lab 4 3