I'm new to the forum and pretty new to programming. I'm taking a Comparitive programming course and working on figuring some of this stuff out. I'm working on a problem that deals with dynamic and static scoping. I'm not looking for someone to answer the question for me or give me the answer. I'm wanting some explaination and guidance on how this stuff actually works. For example:
Consider the following C program:
int x;
int main() {
x = 20;
f();
g();
}
void f() {
int x = 30;
h();
}
void g() {
int x = 40;
h();
}
void h() {
printf("%d\n",x);
}
If static scoping is used, what is the result? If dynamic scoping is used, what is the result? Which scope rule is actually used by C language?If I understand this correct. The results under dynamic scoping would be x = 40 and static would be x = 20. :confused: Also I believe if I found the correct information C programming uses static scoping and not dynamic. The problems I am posting are not homework assignments, they are problems that are given for review and understanding so they do not get submitted for a grade. Let me know if you can help. Thanks.
Edited by Orjan, 20 October 2009 - 08:28 AM.
Use code tags for showing code


Sign In
Create Account


Back to top









