Programming Languages Final Simulation With Answers
The document is a final exam simulation for programming languages, containing various types of questions including explanations, drawings, fill-in-the-blanks, and true/false questions. Key concepts covered include referential transparency, pass-by-value vs. pass-by-reference, runtime stack structure, activation records, and control flow statements. Each question is accompanied by correct answers and notes for clarification.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views4 pages
Programming Languages Final Simulation With Answers
The document is a final exam simulation for programming languages, containing various types of questions including explanations, drawings, fill-in-the-blanks, and true/false questions. Key concepts covered include referential transparency, pass-by-value vs. pass-by-reference, runtime stack structure, activation records, and control flow statements. Each question is accompanied by correct answers and notes for clarification.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
Programming Languages - Final Exam
Simulation (with Answers)
A. Explanation Questions (2 Questions) 1. Explain the concept of Referential Transparency. Give an example. ✅ Answer: Referential transparency means an expression always returns the same value for the same input and has no side effects. 📝 Note: Enables easier reasoning about program behavior. 📘 Chapter: 7 – Final %70
2. Describe the difference between pass-by-value and pass-by-reference.
✅ Answer: Pass-by-value sends a copy of the variable, while pass-by-reference sends the actual variable address allowing modification. 📝 Note: Reference passing changes original value; value passing does not. 📘 Chapter: 9 – Final %70
B. Drawing Questions (2 Questions)
3. Draw the runtime stack if the function call order is: main → process() → compute() → print() ✅ Answer: Top of Stack - print Activation Record - compute Activation Record - process Activation Record - main Activation Record Bottom of Stack 📝 Note: Stack operates in LIFO order; last called is on top. 📘 Chapter: 10 – Final %70
4. For the following function, draw the activation record layout:
void sub(float total, int part) { int list[5]; float sum; } ✅ Answer: - sum - list[4] to list[0] - part - total - dynamic link - return address 📝 Note: Local variables go on top, then parameters, then control info. 📘 Chapter: 10 – Final %70
C. Fill in the Blanks (10 Questions)
5. Short-circuit evaluation is used with _________ and _________ operators. ✅ Answer: && and || 📝 Note: Stops evaluation early. 📘 Chapter: 7
6. The method of evaluating expressions without changing variable state is called
________. ✅ Answer: Referential Transparency 📝 Note: No side effects. 📘 Chapter: 7
7. In C, assigning a float to an int involves ________.
✅ Answer: Coercion 📝 Note: Type conversion with possible truncation. 📘 Chapter: 7
8. if-else and switch statements are types of ________ statements.
❌ False 📝 Note: Stack is LIFO (Last In First Out). 📘 Chapter: 10 21. A function call always creates a new activation record. ✅ True 📝 Note: Needed for tracking context. 📘 Chapter: 10