GATE Exam  >  GATE Questions  >  What is the return value of f(p,p) if the val... Start Learning for Free
What is the return value of  f(p,p) if the value of p is initialized to 5 before the call? Note
that the first parameter is passed by reference, whereas the second parameter is passed by
value.
int f (int &x, int c) {
c= c- 1;
if (c= 0) return 1;
x = x+ 1;
return f (x,c )* x;
}
  • a)
    3024
  • b)
    6561
  • c)
    55440
  • d)
    161051
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
What is the return value of f(p,p) if the value of p is initialized to...
View all questions of this test
Most Upvoted Answer
What is the return value of f(p,p) if the value of p is initialized to...
&x, int y) {
x = x + y;
y = y + 1;
return x + y;
}

If p is initialized to 5 before the call, then the value of p will be passed by reference to the function. This means that any changes made to p within the function will also affect the value of p outside the function.

When f(p,p) is called, the value of p is 5 and is passed by reference as the first parameter. The second parameter is also initialized to 5.

Within the function, x is a reference to the same memory location as p, so x is also equal to 5. The first line of the function adds y (which is also 5) to x, so now x (and p) is equal to 10.

Then, y is incremented by 1, so y is now equal to 6.

Finally, the function returns the sum of x and y, which is 16 (10+6).

So the return value of f(p,p) if p is initialized to 5 before the call is 16.
Explore Courses for GATE exam
What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer?
Question Description
What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer?.
Solutions for What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer?, a detailed solution for What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What is the return value of f(p,p) if the value of p is initialized to 5 before the call? Notethat the first parameter is passed by reference, whereas the second parameter is passed byvalue.int f (int &x, int c) {c= c- 1;if (c= 0) return 1;x = x+ 1;return f (x,c )* x;}a)3024b)6561c)55440d)161051Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev