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
A company that hires only American Indians is practicing
Mashutka [201]
What’s the question ?
7 0
2 years ago
Read 2 more answers
What is the definition of the word uproot?
avanturin [10]
Uproot means to pull something out of the ground, when a tree is uprooted, It is pulled out of the ground
4 0
2 years ago
We can see spreadsheet results graphically by creating:
Inessa [10]
Please ask a question.
5 0
3 years ago
A user calls your help desk and says that he is trying to configure his Word document so that the text within his paragraphs is
katrin [286]

Answer:

The best answer would be

Explanation:

To access this command ...

Select the Format tab - Properties - Paragraph properties - Bleeds and spaces

7 0
3 years ago
Memorex Disks sells computer disk drives with right-of-return privileges. Returns are material and reasonably predictable. Memor
pychu [463]

Memorex should: iv. record a refund liability in the year of the sale.

<h3>What is a right-of-return privilege?</h3>

A right-of-return privilege can be defined as a special right, advantage or entitlement that is accorded to a customer, which avails them an opportunity to return a product they have purchased.

Since Memorex Disks offers its customers right-of-return privileges, it is expected that it should record a refund liability in the year of the sale i.e recording an allowance for sales returns in the year the sale was made.

Read more on right-of-return privilege here: brainly.com/question/17165436

#SPJ1

5 0
2 years ago
Other questions:
  • "the file that specifies how netbeans builds and deploys the application when you run the application is called the ____________
    8·1 answer
  • Encyclopedia.com is considered to be
    15·1 answer
  • Which method deletes a footer from a document?
    9·2 answers
  • If you are working on a document and want to have Word automatically save the document every minute, what steps should you use t
    13·1 answer
  • You are system administrator with hundreds of host workstations to manage and maintain. You need to enable hosts on your network
    14·1 answer
  • ____________________ is the primary code humans use to communicate. (Points : 1
    9·1 answer
  • Technologies can offer safety and protection for people
    11·1 answer
  • What is the diffrent between ibm pc and ibm compatibles in table:​
    11·1 answer
  • PLZZZZZZZZZZZZZZZ HELP ME OUT!!!!! I SICK AND TIRED OF PEOPLE SKIPING MY QUESTION WHICH IS DUE TODAY PLZ ANSWER ALL OFIT!!!!
    10·1 answer
  • Suppose that a particular algorithm has time complexity T(n) = 3 \times 2^nT(n)=3×2 ​n ​​ and that executing an implementation o
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!