Question

2. Consider the following programs (using Cs syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf(%d, %d\n,a,b); void foobar) } printf(%d, %d\n, a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf (%d, %d\n, a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution :

¥ Output coita Static Scoping Outputn ron first Pint statcment m etier) firs 2. ,3ien updatig value ot bin felon) Fm Moun fan

if you have any doubts then you can ask in comment section.

Add a comment
Know the answer?
Add Answer to:
2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment: Show the symbol table for the following C programs at the printf lines (a) using lexi...

    Assignment: Show the symbol table for the following C programs at the printf lines (a) using lexical scope and (b) using dynamic scope. What does the program print using each kind of scope rule? Program 1: const int b = 10; int foo() {    int a = b + 10;    return a; } int bar() {    int b = 4;    return foo(); } int main() {    printf(“foo = %d\n”,foo());    printf(“bar = %d\n”,bar());    return 0; } Program 2: int a;                 void...

  • Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void)...

    Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...

  • Consider the following program written in C syntax int a , b , c ; //...

    Consider the following program written in C syntax int a , b , c ; // first declaration void g() { print(a,b,c); } int f(int a) // parameter declaration { int b; // second declaration b = a + 1; g(); // first call { int a; // third declaration int c; // fourth declaration c = b; a = b + c; g(); // second call } g(); // third call return a + b ; } int main()...

  • B) The following code is given. Determine the outputs if scoping is static and dynamic. static...

    B) The following code is given. Determine the outputs if scoping is static and dynamic. static scope output dynamic scope output #include <stdio.h> void function1(int); void function(int); int function(void); intx=10; main() { functioni(x); function2x); void function1(int y) { int x=y+5; printf("x=%d in function1 \n",function()); void function(int y){ int x=y+10; printf("x=%d in function1 \n", function()); int function(){ return x;

  • 1. What is the output of the following program? include <stdio.h> int wilma (int x) if...

    1. What is the output of the following program? include <stdio.h> int wilma (int x) if (x<5) x = 7; return (x) int main (void) int x-1 x=wilma (x) ; printf ("%d", x); return (0) b)3 c) 4 d) 7 a) 1 e) none of these

  • Consider the following code: int a:=10 //global int b:=12 //global proc F a:= a-b proc P...

    Consider the following code: int a:=10 //global int b:=12 //global proc F a:= a-b proc P (M:proc) int a:=2 M() proc K int b:=3 P(F) K() //main program print(a) //built in function a- what does this code print if it uses dynamic scoping and deep binding? b- what does this code print if it uses dynamic scoping and shallow binding?

  • Consider the following Java classes: class A{ public int foo () { return 1; } public...

    Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • Hi, I want to devise an experiment to verify that F# is using static scooping as...

    Hi, I want to devise an experiment to verify that F# is using static scooping as opposed to dynamic scoping. here is a similar program written in C language: int n = 3; int f() { return n; } // f must refer to an external (free) variable int main() { int x = 2; printf("%d", f()); // prints 3 if static, 2 if dynamically scoped return 0; } However, there's no main in F#. Thank you.

  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT