Give the output of the following program assuming static scoping   #include using namespace std;   int total = 5; int c = 3;   int fun1(int); int fun2(int);   int main() { int x = 2; int y = 8; cout << " variables x y and c have values: " << x <<" " << y << " " << c << endl; cout << "main: fun1(x) = " << fun1(x)  << endl; cout << " After Call to fun1(x) variables x y and c have values: " << x <<" " << y << " " << c << endl;   return 0; }   int fun1(int a) {    int b = 6;    int c = 3;       b = total + c + a;    cout << "in fun1: b= " << b << endl;    cout << "in fun 1 after call to fun2(total) the return value is " << fun2(total) << endl;    return (b); } int fun2(int w) {      c = c * 2; total = total + w + c; cout << "in fun2: total= " << total << endl; return(c); }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 2SA
icon
Related questions
Question

 Give the output of the following program assuming static scoping

 

#include <iostream>

using namespace std;

 

int total = 5;

int c = 3;

 

int fun1(int);

int fun2(int);

 

int main()

{

int x = 2;

int y = 8;

cout << " variables x y and c have values: " << x <<" " << y << " " << c << endl;

cout << "main: fun1(x) = " << fun1(x)  << endl;

cout << " After Call to fun1(x) variables x y and c have values: " << x <<" " << y << " " << c << endl;

 

return 0;

}

 

int fun1(int a)

{

   int b = 6;

   int c = 3;

  

   b = total + c + a;

   cout << "in fun1: b= " << b << endl;

   cout << "in fun 1 after call to fun2(total) the return value is " << fun2(total) << endl;

   return (b);

}

int fun2(int w)

{

     c = c * 2;

total = total + w + c;

cout << "in fun2: total= " << total << endl;

return(c);

}

 

Expert Solution
Step 1

This is a C++ program that defines two functions, fun1 and fun2, and a main function that calls fun1 and prints the values of some variables before and after the function call.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr