Given three pieces of C++ code, run and observe output (note: write a main() as test...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given three pieces of C++ code, run and observe output (note: write a main() as test driver in order to run; you don't have to turn in your program for this homework, just observe the results) then answer the questions below. (1) void swap (int x, int y) { int t = x; x = y; y = t; return; } int a = 10, b = 20; swap(a,b); //now print a and b (3) void swap (int& x, int& y) { int t = x; X = Y; y = t; return; (2) void swap (int *px, int *py) { int t = *px; } int a = 10, b = 20; swap(a,b); //now print a and b *px = *py; *py = t; return; } int a = 10, b = 20; swap (&a,&b); //print a and b Question (a): what is the parameter passing method implemented/supported by the language for each of the above code? Question (b): Run the code and observe the results. Which code(s) swap two values? Which code(s) don't? Why - briefly explain. Given three pieces of C++ code, run and observe output (note: write a main() as test driver in order to run; you don't have to turn in your program for this homework, just observe the results) then answer the questions below. (1) void swap (int x, int y) { int t = x; x = y; y = t; return; } int a = 10, b = 20; swap(a,b); //now print a and b (3) void swap (int& x, int& y) { int t = x; X = Y; y = t; return; (2) void swap (int *px, int *py) { int t = *px; } int a = 10, b = 20; swap(a,b); //now print a and b *px = *py; *py = t; return; } int a = 10, b = 20; swap (&a,&b); //print a and b Question (a): what is the parameter passing method implemented/supported by the language for each of the above code? Question (b): Run the code and observe the results. Which code(s) swap two values? Which code(s) don't? Why - briefly explain.
Expert Answer:
Answer rating: 100% (QA)
a The parameter passing method implementedsupported by the language for each of the above code snippets are as follows 1 Passbyvalue The function swap ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these operating system questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Current Attempt in Progress Joseph Taylor recorded the following transactions during the month of April. Apr. 3 16 20 Cash Service Revenue Rent Expense Cash Salaries and Wages Expense Cash 3,020 690...
-
The time and energy required for careful revision can often benefit you or your company directly. For example, reader-friendly product descriptions will increase the probability that website visitors...
-
Why are viruses so much smaller than the cells they infect?
-
Consider the stock of Examples 14.3 and 14.4, which has \(\sigma=.20\) and an initial price of \(\$ 62\). The interest rate is \(10 \%\), compounded monthly. Consider a 5-month option with a strike...
-
On January 1, 2018, Allied Industries leased a high-performance conveyer to Karrier Company for a four-year period ending December 31, 2021, at which time possession of the leased asset will revert...
-
You have completed ACCT Advanced Tax. Four of your friends recognize that you are now a legal and tax expert. They ask you for advice as to whether they should form an S Corporation. Is the S Corp...
-
1. The CEO has asked you to help her decide whether to use LIFO or FIFO for inventory casting. Compute the gross profit earned by the company for both LIFO and FIFO 2 The CEO's bonus is calculated...
-
The system shown in the schematic represents a model two-story building: Take m = 1 104 kg, m = 3 104 kg, k = 4 105 N/m, k = 2 105 N/m a) Derive the equations of motion of the system and represent...
-
Go to the Hubbard OBrien Economics Blog and read the following post titled, How the Effects of the Covid-19 Recession Differed Across Business Sectors and Income Groups,...
-
On 1 July 2019, Weiland Pty Ltd owned several farming vehicles that had cost a total of $155 000. Accumulated depreciation on these vehicles to 1 July 2019 amounted to $73 000. On 30 September 2019,...
-
Acetic acid is to be removed from an aqueous solution by allowing droplets of the acetic acid-water solution to fall through a column of benzene. The droplets initially contain 1.0 weight % of acetic...
-
Dolphins and other marine mammals are able to maintain a surprisingly high body temperature even though they are swimming in ocean water at 4C. Since the dolphin tail has a large surface area, much...
-
Some people are concerned about "electromagnetic smog" and install meshes on their windows to absorb electromagnetic waves. A particular product advertises "50-dB attenuation in the range from \(10...
-
The following is Trial Balance of Shri Om as on 31 March 2017. You are required to prepare Balance Sheet as per Schedule III of Companies Act, 2013 as on that date after making necessary adjustments:...
-
Express mass density in kg/m3 and weight density in lb/ft3. 1. Find the mass density of a chunk of rock of mass 215 g that displaces a volume of 75.0 cm3 of water. 2. A block of wood is 55.9 in. x...
-
In the U.S., Presidential elections are not won by the candidate who wins the popular vote nationally. (If they were won in this way, Al Gore would have become President in 2000.) Rather, each state...
-
Basket A contains 1 unit of x1 and 5 units of x2. Basket B contains 5 units of x1 and 1 unit of x2. Basket C contains 3 units of x1 and 3 units of x2. Assume throughout that tastes are monotonic. A:...
-
Fishing in the Commons: In the text, we introduced the notion of the Tragedy of the Commons and found its source in the emergence of externalities when property rights are not well established. This...
-
What are the differences among an onsite team, a virtual team, a task force, and a committee? What are some of the potential differences in dynamics between people in these different groups?
-
What are the benefits of implementing programs to address cultural competence within a health care organization? What are the costs of not implementing such programs?
-
Over the past month, every member of the Intravenous (IV) Therapy Team has complained to you about the IV Team supervisor. Her direct reports, all RNs, agree that she is technically superb. However,...
Study smarter with the SolutionInn App