Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pad 21% 23:54 cs.iit.edu 2 of 3 [15-3 * 5 points] (Similar to Problem 3.5, p.167

ID: 3728867 • Letter: P

Question

Pad 21% 23:54 cs.iit.edu 2 of 3 [15-3 * 5 points] (Similar to Problem 3.5, p.167.) A forward reference is a use of a name before its definition. Related to this is the question of where the scope of a declaration takes effect -- from the point of declaration? From the left curly brace beginning the block (i.e., the whole block)? Read Problem 3.5 to find the answer to these two questions for C, C#, and Modula-3 a. For the program below, if we use C rules, do either of declarations (at decl 1 or 2) cause a forward reference error? If not, what values for a and b are passed to f at labels 1 and 21 What if C# rules are used? What if Modula-3 rules are used? b. c. #include int main() int a = 1; int b=2: int c-3; int a = 3*b; f(a, b, c); int b = 3*c: f(a, b, c); int c = 4; // decl 1 // label 1 // decl 2 // label 2

Explanation / Answer

a) In C language, there will not be an forward reference error at decl 1 and decl 2.

at label 1 , a= 6, b=2 are passed to f.

and label 2, a=6 ,b=9 are passed to f.

(given f is a well defined function or there will be an error).

b) In C# language, there will  be an forward reference error at decl 1 and decl 2.

c) In Modula-3, there will  be an forward reference error at decl 1 and decl 2.