Question: 4. Consider the following program, written in C. int i = 10; void p(void) { printf(G1: %d , i); i++; printf(G2: %d , i); }

4. Consider the following program, written in C.

int i = 10;

void p(void) { printf("G1: %d ", i); i++; printf("G2: %d ", i); } 
void h(int i) { printf("F1: %d ", i); i++; p(); printf("F2: %d ", i); } 
int main( ) { int i = 100; printf("N1: %d ", i); h(i); printf("N2: %d ", i); p(); printf("M3: %d ", i); } 

a) Complete the following trace, by showing what gets printed when Cs usual static scoping is used.

N1: F1: G1: G2: F2: N2: G1: G2: N3: 

4

b) Assume NewC is a new programming language that is identical to C, except that it uses dynamic scoping. Complete the following trace, by showing what gets printed when NewC is used.

N1: F1: G1: G2: F2: N2: G1: G2: N3: 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!