GATE | GATE-CS-2014-(Set-2) | Question 52
Consider the JAVA function given below.
Java
static int f( int j){
int i = 50 ;
int k;
if (i == j){
System.out.print( "something" );
k = f(i);
return 0 ;
}
else return 0 ;
}
|
Which one of the following is TRUE?
(A)
The function returns 0 for all values of j.
(B)
The function prints the string something for all values of j.
(C)
The function returns 0 when j = 50.
(D)
The function will exhaust the runtime stack or run into an infinite loop when j = 50
Answer: (D)
Explanation:
When j is 50, the function would call itself again and again as neither i nor j is changed inside the recursion.
Hence Option (D) is the correct answer.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...