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
An independent penetration testing company is invited to test a company's legacy banking application developed for Android phone
erastovalidia [21]

2010s is the one who created the iPhone

8 0
3 years ago
In this lab you will learn about the concept of Normal Forms for refining your database design. You will then apply the normaliz
noname [10]

Answer:

I don't know

Explanation:

is about knowing how to make use of the refinery

7 0
3 years ago
Select the correct answer from each drop-down menu. A company is recruiting for a web designer. What kind of candidate should th
prisoha [69]

Answer:a

Explanation:

8 0
3 years ago
Read 2 more answers
Sound effects are located within the Microsoft® Office applications. In the Insert ribbon, what would you select to find pre-pro
babymother [125]
Sometimes clip art has sound files in them, it may have gotten updated though, that answer is the only one that could work.
7 0
3 years ago
Literacy is best defined as knowing how to: (Points : 1
Soloha48 [4]
Depends on what kind of literacy you are referring to, (computer, health, etc). Since this was asked under computers and technology, I will base my answer on Computer Literacy.

Computer Literacy basically means how much you know about using a computer. Using applications such as Internet Explorer and Microsoft word, or simply typing a document is a form of computer literacy.
6 0
4 years ago
Other questions:
  • Which statement about information published on the internet is true?
    9·2 answers
  • You are writing an email to a potentional employer about a job opportunity. What can you do to make sure the email reflects your
    15·2 answers
  • What is one way to measure technological progress?
    5·1 answer
  • You need to provide connectivity between two buildings without running any cables. You decided to use two 802.11ac APs to provid
    14·1 answer
  • How is a source file different from a "listing file"?
    5·1 answer
  • Speed in a given direction is called
    12·2 answers
  • What is the value of the result after the following statement is executed? int result = 2 + 3 + 4 ;
    7·1 answer
  • How much weeks are in one year ​
    5·2 answers
  • Which of the following is not a true statement? a. Data flow diagrams and flowcharts are difficult to prepare and revise using s
    10·1 answer
  • In which step is a metaphor used in planning a multimedia presentation
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!