0% 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.

Uploaded by

82dn66qxff
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

82dn66qxff
Copyright
© © All Rights Reserved
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.


✅ Answer: Selection
📝 Note: Control flow choice.
📘 Chapter: 8

9. The runtime memory area for function calls is the ________.


✅ Answer: Stack
📝 Note: Holds activation records.
📘 Chapter: 10

10. Pass-by-________ allows a function to modify the caller’s variable.


✅ Answer: Reference
📝 Note: Uses variable address.
📘 Chapter: 9

11. A CFG defines the ________ of a programming language.


✅ Answer: Syntax
📝 Note: CFG = Context-Free Grammar.
📘 Chapter: 3 – Vize %30
12. { } in EBNF means zero or more ________.
✅ Answer: Repetitions
📝 Note: Loop-like grammar.
📘 Chapter: 3 – Vize %30

13. An activation record includes parameters and ________.


✅ Answer: Local Variables
📝 Note: Temporary and fixed data.
📘 Chapter: 10

14. The operator == has ________ precedence than +.


✅ Answer: Lower
📝 Note: Comparison after addition.
📘 Chapter: 7

D. True / False Questions (10 Questions)


15. Short-circuit evaluation always evaluates all conditions.
❌ False
📝 Note: Stops early if result is known.
📘 Chapter: 7

16. Pass-by-value allows the function to change the caller’s variable.


❌ False
📝 Note: Only modifies a copy.
📘 Chapter: 9

17. CFG defines the semantics of a language.


❌ False
📝 Note: CFG defines syntax, not meaning.
📘 Chapter: 3 – Vize %30

18. [x] in EBNF means x occurs zero or one time.


✅ True
📝 Note: Optional element in grammar.
📘 Chapter: 3 – Vize %30

19. Pass-by-reference allows external variable modification.


✅ True
📝 Note: Directly changes caller’s data.
📘 Chapter: 9

20. Stack is FIFO (First In First Out) structure.


❌ 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

22. else always binds to the farthest if.


❌ False
📝 Note: Binds to nearest if.
📘 Chapter: 8

23. All operators in C have the same precedence.


❌ False
📝 Note: Precedence varies (e.g., * > +).
📘 Chapter: 7

24. Assignment operators in C associate right to left.


✅ True
📝 Note: a = b = c; is valid.
📘 Chapter: 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy