Question

2:31 $32% X 324 325 14) Given the following function definition: void calc (int a, int& b) intc; C = a + 2; a = a* 3; b = c +

Can someone please explain to me this? I'm having a hard time understanding it. thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output:

E) None of these

The actual output is 1 5 3 (which is not mentioned in the given options )

" As you pass any argument by using call by reference then changes made to the parameter affect the passed argument"

Here, x=1 and y =2 so as you call the calc() where a is normal variable and b is a reference variable so the value of y is assigned to b ie value of b is now 2 so inside the function,

c= a* b = 1 * 2 = 2

a = a * 3 = 1 * 3 = 3

b = c + a = 2 + 3 = 5

As I said earlier

" As you pass any argument by using call by reference then changes made to the parameter affect the passed argument"

so the value of b is 5 so the value of y also becomes 5

so as you print the values of x, y and z then the output is x=1, y=5, z=3.

If you remove & ie if treat b as a normal variable then the output will be 1 2 3,

because calc() function doesn't return anything so it will display the values of x,y, and z;

Add a comment
Know the answer?
Add Answer to:
Can someone please explain to me this? I'm having a hard time understanding it. thank you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show work and design. I'm having a hard time understanding the material. Thank you! Q4....

    Please show work and design. I'm having a hard time understanding the material. Thank you! Q4. Use a 4-to-1 multiplexer and any extra logic gates you may need to implement the function f(a, b, c, d)-2 (1, 3, 5, 6, 8, 11,15). Use variables c and d as the control inputs to the multiplexer.

  • I know the right answers by using a compiler. However, can you please explain each step...

    I know the right answers by using a compiler. However, can you please explain each step and how you get the correct answer. Thank you in advance. Output: E = 1 F = 7 G = 11 H = 14 W = 5 X = 6 Problem 7 #include <iostream> #include <cmath> using namespace std; void F1(int,int,int,int&); void F2(int,int&,int&,int&); int main ( void ) { int E=1,F=2,G=3,H=4,W=5,X=6;    F1(E,F,G,H);    F2(E,F,G,H);    cout << "E = " << E <<...

  • can you show me the details please. thank you 13. What is the output of the...

    can you show me the details please. thank you 13. What is the output of the following program? #include <iostream.h> void main() { int x; 1/ declare variable for (x = 1; x <= 5; x++) { // loop 5 times switch (x) { case 1: cout << x < // switch value of // if "x" is equal // display "X", but endl; case 2: cout << x << endl; // if "x" is equal // display "x", but...

  • For an ungraded C++ lab, we have practice with structs. I'm having a hard time calling...

    For an ungraded C++ lab, we have practice with structs. I'm having a hard time calling the functions relating to our book struct correctly. The issues lie in main(). Here is the .cpp: #include "book.h" void add_author(Book& book){         if (book.num_auth==3){             std::cout<<"\nA book can't have more than 3 authors!";         }         else{             std::cout<<"\nAdd Author: ";             getline(std::cin, book.authors[book.num_auth]);             book.num_auth++;         } }; void remove_last(Book& book){         if(book.num_auth<=1){             std::cout<<"\nA book must have at least 1 author!";...

  • How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using...

    How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using namespace 4. 5 int main() std; unsigned int x = 0b01101100; 8 9 10 12 13 14 15 16 17 18 19 20 21 unsigned int z = 0x12345678; unsigned int e 0x7; unsigned int w = 0x87654321; unsigned int =0x123; int 1; int 92; int Q3; int Q4; Q1=x&y; cout << bitset<8> (Q1) << endl; Q2=-(x| y); cout << bitset<8>(Q2) << endl; Q3=(z...

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • I'm getting an Error: LNK1561: entry point must be defined. Can someone edit it with using...

    I'm getting an Error: LNK1561: entry point must be defined. Can someone edit it with using the basic iostream and string libraries, only basic lib. In a population, the birth rate and death rate are calculated as follows: Birth Rate = Number of Births ÷ Population Death Rate = Number of Deaths ÷ Population For example, in a population of 100,000 that has 8,000 births and 6,000 deaths per year, Birth Rate = 8,000 ÷ 100,000 = 0.08 Death Rate...

  • (C++) Given the following code, please help me answer these three parts and please explain as...

    (C++) Given the following code, please help me answer these three parts and please explain as simply as you can. 1.) How many iterations of the innermost loop? (please show calculation) 2.) What is the largest output? 3.) How many zeroes at the start? (please show/explain calculation) for (int y 0; y 〈 4; y++) for (int z 0: z 〈 5; z++) cout << x * y * z くく endl;

  • Can someone explain how to get this output by hand? Consider the code shown at left...

    Can someone explain how to get this output by hand? Consider the code shown at left below. What is the output of the following C++ program segment, called with confuseDriver()? Write down your answer in the rectangle at right below. Print legibly. Write answer in this box: int s-1, y-3; void confusel (int y, int s) s++i void confuse2 (int b, int &s) s=b+2; void confuse3 (int &a, int &s) s++i void confuseDriver () int y-1; confusel( s, y) confuse2...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT