Data Structure Questions and Answers-Length of a String using Recursion

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Length of a String using Recursion

Congratulations - you have completed Data Structure Questions and Answers-Length of a String using Recursion.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following iterative implementation to find the length of the string:

#include<stdio.h> int get....len(char *s) { int len = 0; while(.....) len++; return len; } int main() { char *s = "harsh"; int len = get....len(s); printf("%d", len); return 0; }

Which of the following lines should be inserted to complete the above code?

A
s[len-1] != 0
B
s[len+1] != 0
C
s[len] != '
D
none of the mentioned
Question 1 Explanation: 
The line "s[len] != '\0'" should be inserted to complete the above code.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the output of the following code?

#include<stdio.h> int get....len(char *s) { int len = 0; while(s[len] != '\0') len++; return len; } int main() { char *s = "lengthofstring"; int len = get....len(s); printf("%d", len); return 0; }
A
14
B
0
C
Compile time error
D
Runtime error
Question 2 Explanation: 
The program prints the length of the string "lengthofstring", which is 14.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the time complexity of the above code used to find the length of the string?
A
O(1)
B
O(n)
C
O(n2)
D
O(logn)
Question 3 Explanation: 
The time complexity of the code used to find the length of the string is O(n).

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the output of the following code?

#include<stdio.h> int get....len(char *s) { int len = 0; while(s[len] != '\0') len++; return len; } int main() { char *s = ""; int len = get....len(s); printf("%d", len); return 0; }
A
0
B
1
C
Runtime error
D
Garbage value
Question 4 Explanation: 
The program prints the length of an empty string, which is 0.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Which of the following can be the base case for the recursive implementation used to find the length of a string?
A
if(string[len] == 1) return 1
B
if(string[len+1] == 1) return 1
C
if(string[len] == '
D
if(string[len] == '\0') return 1
Question 5 Explanation: 
"if(string[len] == '\0') return 0" can be used as base case in the recursive implementation used to find the length of the string.

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.