1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BigorU [14]
3 years ago
8

Given the following function definition:

Computers and Technology
1 answer:
neonofarm [45]3 years ago
4 0

The question is incomplete! Complete question along with its step by step answer is provided below!

Question:

Given the following function definition:

void calc (int a, int& b)

{

int c;

c = a + 2;

a = a * 3;

b = c + a;

}

x = 1;

y = 2;

z = 3;

calc(x, y);

cout << x << " " << y << " " << z << endl;

What is the output of the following code fragment that invokes calc?

a. 1 2 3

b. 1 6 3

c. 3 6 3

d. 1 14 9

e. None of these

Answer:

b. 1 6 3

Explanation:

In the given problem we have a function void calc which takes two input arguments a and b and updates its values according to following equations

c = a + 2;

a = a * 3;

b = c + a;

Then we call this function calc(x,y) by providing test values of

int x = 1;

int y = 2;

int z = 3;

and the output returns the values of x, y and z

cout << x << " " << y << " " << z << endl;

Lets find out what is happening here!

When the program runs we provide x=a=1 and y=b=2

c=a+2=1+2=3

a=a*3=1*3=3

b=c+a=3+3=6

So the updated values of a=x=3 and b=y=6?

NO!

The updated values are a=x=1 and b=y=6

WHY?

There are two ways to pass values

1. Pass by values -> value cannot change  (int a)

2. Pass by reference -> value can change (int& b)

Look at the function void calc (int a, int& b) ;

Here we are passing (int a) as a value and (int& b) as a reference, therefore x remains same x=1 and y gets changed to updated value y=6 and z remains same as z=3 since it wasnt used by function calc(x,y)

The right answer is:

b. 1 6 3

x=1, y=6, z=3

You might be interested in
Why are networked systems beneficial?
Alexxx [7]
A many periphels can be used
5 0
3 years ago
Read 2 more answers
(ANSWER!)
andreev551 [17]

Answer:

it doesn't? maybe it helps by resetting it but other than that I don't think It does anything

4 0
3 years ago
Read 2 more answers
What is the generic term for a device that stores images for long periods of time?
Artemon [7]
I would say 1. Backup drive.
7 0
2 years ago
Read 2 more answers
Methods for preventing/overcoming group conflict include all EXCEPT:
kondor19780726 [428]

Answer:

recognizing that gender differences are a myth.

Explanation:

The options are:

  • active listening.
  • recognizing that gender differences are a myth.
  • structured debate.
  • building cross-cultural understanding

Without active listening, structured debate, and cross-cultural understanding group conflict are definitely on the card. However, no one now is concerned about gender differences. As now both the genders are already having the equal status in at least developed countries. However, this too can play a role in avoiding group conflict. However, since this is not that important considering the current context, this looks like being the correct option here. Hence, the above mentioned in the answer section is the correct option.

7 0
3 years ago
JAVA Code:
Burka [1]
Dear ,you should ask it on stackoverflow and geekforgeelks , not here
6 0
3 years ago
Other questions:
  • Professional photographers often use the lowest quality settings on their cameras since this can be reversed in Photoshop.
    7·2 answers
  • Smart art can be used to create _____that highlights relationships betweeen two items
    8·2 answers
  • Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too
    5·1 answer
  • When subjects are given two drinks but not told what they are drinking in order to get accurate results on which is the better t
    6·1 answer
  • Direct Mapped Cache. Memory is byte addressable. Fill in the missing fields based upon the properties of a direct-mapped cache.
    6·1 answer
  • What is the encryption cipher that was the precursor to des??
    5·1 answer
  • It is impossible to use a computer without a mouse. Is this statement true or false?
    10·1 answer
  • HELPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP!!!
    12·1 answer
  • Write the contributions of dr herman hollerith​
    10·1 answer
  • How does the dns solve the problem of translating domain names like example.com into ip addresses?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!