Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following program. Assume the program compiles and runs. #include using namespace std; void test(int &, int); int z = 0; int main() {

  1. Consider the following program. Assume the program compiles and runs.

#include

using namespace std;

void test(int &, int);

int z = 0;

int main()

{

int count, a, b;

z = 12;

a = 3;

b = 2;

for (count = 1; count <= 2; count++)

test(a, b);

cout << In main a = << a << b = << b << z = << z << endl;

return 0;

}

void test(int& y, int c)

{

static int x = 0;

y = 10;

z = z + 1;

x = x + 2;

y = y + 1;

c = c + 1;

cout << "Inside test x = " << x << " and y = "

<< y << and z = << z << and c = << c << endl;

}

Answer the following questions:

  1. What is the output? Consider variable scope.
  2. Considering the function test, parameter 1 is called by reference. What is passed into the function for parameter 1, i.e., what does parameter 1 receive?parameter 1 receives is pass by reference argument. This type of argument shares reference of the main variable. In this case if argument value changed inside method, it will reflect on the main variable
  3. Again, considering the function test, parameter 2 is called by value. What occurs in memory for parameter 2 and local variable int x? Hint: consider memory, parameters and local/static variables passing by value. here content of the variable passed as argument. so in this case if argument value changed inside method, main variable will be unchanged.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions