Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The following program fragment is written in ... Start Learning for Free
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.
global int i = 100, j = 5;
void P(x) {
int i = 10;
print(x + 10);
i = 200;
j = 20;
print (x);
}
main() {P(i + j);}
If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are
  • a)
    115, 220
  • b)
    25, 220 
  • c)
    25, 15
  • d)
    115, 105
Correct answer is option 'B'. Can you explain this answer?
Most Upvoted Answer
The following program fragment is written in a programming language th...
Explanation:

The given program is written in a programming language that allows global variables and does not allow nested declarations of functions. The program uses dynamic scoping and call by name parameter passing mechanism.

Let's go through the program step by step to understand the flow and the values printed.

1. Global Variables:
- i = 100
- j = 5

2. Function P(x):
- This function takes a parameter x.
- It declares a local variable i and initializes it to 10.
- It prints the value of x + 10.
- It assigns the value 200 to the global variable i.
- It assigns the value 20 to the global variable j.
- It prints the value of x.

3. main():
- This is the main function.
- It calls the function P with the parameters i and j.
- Since the call by name parameter passing mechanism is used, the actual parameters i and j are not evaluated before the function call. Instead, they are passed as expressions.
- Therefore, when P is called with the parameters i and j, the expressions i and j are passed as arguments.

4. Execution:
- P is called with the parameters i and j.
- The value of x is the expression i + 10, which evaluates to 100 + 10 = 110.
- The first print statement prints 110.
- The value of x is the expression i + 20, which evaluates to 100 + 20 = 120.
- The second print statement prints 120.

5. Final Values:
- The global variable i is assigned the value 200 in the function P.
- The global variable j is assigned the value 20 in the function P.

Conclusion:

The values printed by the program are 110 and 120, which matches option B: 25, 220.
Free Test
Community Answer
The following program fragment is written in a programming language th...
In dynamic scoping, the local values are considered and variables are initialised at run time.
Since x = i + j and in P(x), i = 200 and j = 20;
x = 200 + 20 = 220
Print (x + 10)
x = i + j + 10
x = 10 + 5 + 10 = 25
So, 25 and 220 will be printed.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer?
Question Description
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer?.
Solutions for The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer?, a detailed solution for The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions.global int i = 100, j = 5;void P(x) {int i = 10;print(x + 10);i = 200;j = 20;print (x);}main() {P(i + j);}If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program area)115, 220b)25, 220c)25, 15d)115, 105Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev