How many times will the function counter() be executed in the following code?
function counter($start, &$stop)
{
if ($stop > $start)
{
return;
}
counter($start--, ++$stop);
}
$start = 5;
$stop = 2;
counter($start, $stop);
Suggested Answer: B
Get Premium 200-710 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
34 comments · newest first
KI
Kimberely
11 months ago
I thought it would be 6, but I see the mistake now.
LA
Laura
12 months ago
Wait, how does $start decrease if it's passed as a parameter?
MA
Mattie
12 months ago
Definitely 4, I checked the logic.
CE
Celia
1 year ago
I think it's 5 times, not 4.
JU
Julene
1 year ago
The function will be executed 4 times.
LO
Long
1 year ago
I feel like the answer might be 5, but I can't quite visualize how the recursion unfolds with those parameters.
YA
Yan
1 year ago
I'm a bit confused about the order of operations here. Does $start-- mean it decreases after the call?
LE
Lettie
1 year ago
I remember a similar question where we had to track recursive calls, and I think it was about 4 times for this one too.
TH
Thurman
1 year ago
I think the function will execute until $stop is greater than $start, but I'm not sure how the decrement and increment affect the counts.
WE
Weldon
1 year ago
This is a good example of a recursive function that can be tricky to reason about. I'll make sure to carefully trace the execution flow and keep track of the variable values to arrive at the correct answer.
CE
Cecilia
1 year ago
I'm not entirely sure about this one. The combination of the conditional and the increment/decrement operators is making it a bit challenging to visualize. I'll need to test this out with some sample values to be confident in my answer.
SU
Susana
1 year ago
Hmm, I'm a bit confused by the pre- and post-increment/decrement operators in the function call. I'll need to work through this step-by-step to make sure I understand what's happening.
MA
Marisha
1 year ago
This looks like a tricky recursive function question. I'll need to carefully trace the function calls to determine the number of times it's executed.
SH
Shaniqua
1 year ago
Okay, I think I've got it. The function will be called 4 times before the base case is reached and the recursion stops.
LI
Lindy
1 year ago
Hmm, I'm a bit confused on this one. I'll need to review the TOGAF concepts again to make sure I understand the difference between a building block, application, and solution architecture.
GA
Gail
2 years ago
Wait, is this a coding exam or a stand-up comedy routine? I'm feeling inspired to write some recursive jokes!
HA
Hayley
2 years ago
This is a tricky one! I bet the instructor is just trying to confuse us. Time to break out the whiteboard and some coffee!
ST
Stanton
1 year ago
C) 5
LA
Layla
1 year ago
B) 4
ED
Edna
1 year ago
A) 3
PR
Princess
2 years ago
D) 6 has to be the right answer. The function calls itself recursively, so it will keep going until the condition is no longer met.
ER
Erick
1 year ago
D) 6
SH
Sharee
1 year ago
C) 5
YO
Yolando
1 year ago
B) 4
IR
Irving
2 years ago
A) 3
DE
Deonna
2 years ago
Hmm, I'm not sure about this one. Let me think it through step-by-step. I'll try to solve it on paper to be sure.
GE
Gerald
2 years ago
I see, I think it's because the function is called recursively until $stop is greater than $start.
VI
Vilma
2 years ago
I believe it will be executed 5 times.
JU
Julio
2 years ago
I think the correct answer is C) 5. The function counter() will be executed 5 times because the loop continues until $stop is greater than $start.
EV
Evangelina
1 year ago
It's B) 4 because the function is called 4 times before the condition is met.
MA
Maddie
1 year ago
Really? I thought it was C) 5 too.
DA
Darell
1 year ago
No, it's actually B) 4.
SO
Socorro
2 years ago
I think the correct answer is C) 5.
GE
Gerald
2 years ago
I think the function will be executed 4 times.