Question

For the Below question please write correct answer as it is asked.

Thanks

A.4 5 pts Please explain each parameter passing method, when to use it, and code a function prototype example Pass-by-lvalue-

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

pass-by-lvalue-reference:
Generally in this methodology we pass pointers instead of variable names so that the changes in the function will effect the variable
let us take an example
here in the following C program intially the values are a= 10 b =20
in the function we swapped the values to a = 20 b = 10
after the function calling the values of a and b are changed a = 20 b = 10
since we have passed the address the values at the addresses are changed

#include<stdio.h>
void swap(int *a,int *b)
{
   int *temp;
   *temp = *a;
   *a = *b;
   *b = *temp;
   printf("the value of a in function %d\n",*a);
   printf("the value of b in function %d\n",*b);
}
int main()
{
   int a = 10,b = 20;
   printf("the value of a before calling the function %d\n",a);
   printf("the value of b before calling the function %d\n",b);
   swap(&a,&b);
   printf("the value of a after calling the function %d\n",a);
   printf("the value of b after calling the function %d\n",b);
   return 0;
}

deepika@deepika-Travel Mate- P243-M: ~/Desktop Terminal File Edit View Search Help deepika@deepika -Travel Mate -P243 -M:~/De

pass-by-const-rvalue-reference:
Generally in this methodology we pass variable names so that the changes in the function will not effect the variable
let us take an example
here in the following C program intially the values are a= 10 b =20
in the function we swapped the values to a = 20 b = 10
after the function calling the values of a and b are still a = 10 b = 20
since we have passed the varable names only the values are not get changed.

#include<stdio.h>
void swap(int a,int b)
{
   int temp;
   temp = a;
   a = b;
   b = temp;
   printf("the value of a in function %d\n",a);
   printf("the value of b in function %d\n",b);
}
int main()
{
   int a = 10,b = 20;
   printf("the value of a before calling the function %d\n",a);
   printf("the value of b before calling the function %d\n",b);
   swap(a,b);
   printf("the value of a after calling the function %d\n",a);
   printf("the value of b after calling the function %d\n",b);
   return 0;
}

deepika@deepika-Travel Mate- P243-M: ~/Desktop Terminal File Edit View Search Help deepika@deepika -Travel Mate -P243 -M:~/De

If you have any doubts please comment and please don't dislike.

Add a comment
Know the answer?
Add Answer to:
For the Below question please write correct answer as it is asked. Thanks A.4 5 pts...
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 explain each parameter passing method, when to use it, and code a function prototype example....

    Please explain each parameter passing method, when to use it, and code a function prototype example. a. Pass-by-rvalue b. Pass-by-const-lvalue-reference

  • A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points...

    A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points to pointer Please code an Ivalue reference to reference *pointer Please code an rvalue reference to reference *pointer Please use what you created, if legal, to change the value of cs to 413. Provide your code or reasoning: A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points to pointer Please code an Ivalue reference to reference *pointer...

  • 1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please...

    1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please show all outputs. Write functions to add one day, another function to add one month, and yet another function to add one year to a Date struct. struct Date { int year; int month; int day; }; Pass Dates by reference when appropriate (i.e., Date& or const Date&). For example, the following function returns by value a new Date instance with one day added...

  • ANY ANSWER IS MUCH APPRECIATED. THANK YOU!! QUESTION 1 ________ are useful for returning more than...

    ANY ANSWER IS MUCH APPRECIATED. THANK YOU!! QUESTION 1 ________ are useful for returning more than one value from a method. Default arguments Parameter lists Reference parameters Named arguments 1 points    QUESTION 2 When you call a ________ method, it executes its code and returns without passing any value back to the program statement that called it. void private terminal value-returning 1 points    QUESTION 3 You can pass string literals as arguments to methods containing  string parameters. True False...

  • URGENT, WILL RATE IF CORRECT! Question 4 5 pts Can we call a function in Python...

    URGENT, WILL RATE IF CORRECT! Question 4 5 pts Can we call a function in Python passing parameters in an order different from that specified by the function definition ? O yes, using parameter keywords O yes, only if no parameter has default values O yes, using positional arguments O no

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • When asked to answer a question, please write the answer clearly. (1) (4 marks.) Use the...

    When asked to answer a question, please write the answer clearly. (1) (4 marks.) Use the least square method to find the best straightline fit to the data points: (-1,1), (1, -1), (2,1), (2, 2).

  • Result inト 9c. (5 pts) Write a function named between that is defined with two parameters. It re...

    in python result inト 9c. (5 pts) Write a function named between that is defined with two parameters. It returns a reference to a tion that has one parameter, which returns whether or not its one parameter is between (inclusive) the two arguments supplied when between is called. For example x between (18,22) and the call x(29) returns True. def between(lower, upper): result inト 9c. (5 pts) Write a function named between that is defined with two parameters. It returns...

  • c++ question i just need answer for this question Dont need to write all program.Thanks Use...

    c++ question i just need answer for this question Dont need to write all program.Thanks Use the following class declaration when answering this question: class Containers w public: void disconnect( const int container_id): private: int count; \\number of container cargo cells used int capacity; \\ total number of container cargo cells int *cargo; \\name of dynamic array }; Implement the function "disconnect with the given prototype in the class declaration above. The function will remove the item that matches the...

  • please help with this homework, thanks !! NAME CSC 236- ArrayList and Generics coding quz Write...

    please help with this homework, thanks !! NAME CSC 236- ArrayList and Generics coding quz Write Java statements to odd the integers 1001, 1100, and 1110 to the resulting ArrayList from question 4 above. 5) 6) Write the Java statement to display the size of The resulting ArrayList from question 5 above. Write Java statements that use a for each loop to cycle through all the elements in on ArrayList of doubles named grades. 7) Write a Java method named...

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
ADVERTISEMENT