Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 887727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:16:38+00:00 2026-05-15T13:16:38+00:00

I always get confused between the static and dynamic scoping and hence need someone

  • 0

I always get confused between the static and dynamic scoping and hence need someone to examine my evaluation. Following is the example code:

int x = 1;

procedure P(i) {
int x = 1;
i++;
Q(i);
}

procedure Q(j) {
j = j + x;
}


P(x)
print x

In static scoping, we always look at the placement of the function/procedure to understand its scope. Hence,

1 main is the outermost scope of the program
2 > Procedures P and Q are within main and hence they shall always refer to the variables in the main function if not defined in its local scope. This is irrespective of the manner of procedure call
3 > In the example, procedure P has variable x defined. Hence it shall shadow the main's x.
4 > Procedure Q does not have variable x defined and hence shall refer to main's x

The output is
1 > For static scoping and pass by value=> 1
2 > For dynamic scoping and pass by value=> 2

3 > For static scoping and pass by reference=> 4
4 > For dynamic scoping and pass by reference=> 3

Please let me know if I have gone wrong somewhere. Also, it will be great if anyone can provide me with useful link on static and dynamic scoping examples such as above.

Thanks,
darkie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:16:39+00:00Added an answer on May 15, 2026 at 1:16 pm

    There’s a number of articles out there. Google is your friend 🙂

    [Edit] After reading through some of those links I think the following is true:

    1. For static scoping and pass by value=> 1
    2. For dynamic scoping and pass by value=> 1
    3. For static scoping and pass by reference=> 4
    4. For dynamic scoping and pass by reference=> 3

    Point 2 should return 1 because you’re passing by value so the x you’re passing in never gets modified.

    Tim Hoolihan has an example which is easier to follow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I always get confused about this. Let's say I have this code. Public
I always get confused with licenses, I'm reading up again, but I'm sure someone
I always get confused. Would someone explain what Reentrant means in different contexts? And
I don't like this code but I always get confused with threads so wanted
I always get confused when I am about to use a bit map to
I am starting to use JPA and I always get confused with the term
This is a very simple question for compiler guys, but I always get confused
Why do I always get the following error from Postgres? syntax error at or
I'm doing the following and always get green pins: pin.pinColor = MKPinAnnotationColorRed; [self.mapView addAnnotation:pin];
While designing the class, I always get confused what to put in Constructor and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.