x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

It is used when you want to make changes in the actual variable and do not want to make a copy of variables and work on them

best example is that of swapping two numbers

main() { int x, y, temp;   printf("Enter the value of x and y\n"); scanf("%d%d", &x, &y);   printf("Before Swapping\nx = %d\ny = %d\n",x,y);   temp = x; x = y; y = temp;   printf("After Swapping\nx = %d\ny = %d\n",x,y);  }

Answer

To Dynamically call different functions depending on requirements.

Answer

When a function make some changes in formal parameter and we want these changes back to actual variable which are passed to the function as argument, then we use call by reference method

Supose we passed a variable A as argument to a function MODIFY(A) , and we want back any modification done in A by function MODIFY, then we need to pass A into function MODIFY by reference.

Answer

The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.

To pass a value by reference, argument pointers are passed to the functions just like any other value. So accordingly you need to declare the function parameters as pointer types as in the following function swap(), which exchanges the values of the two integer variables pointed to, by their arguments.

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer