Select the correct answerWhat will the output of below given code snippet?#include <stdio.h>void Function (char *S){ if (*S && *S !=' ') { Function(S+1); putchar(*S); }} int main(){ char S1[] = "CodeTantra Coding Castle"; Function(S1); return 0;}OptionsGarbage value will be printedPrints "CodeTantra Coding Castle"Prints "eltsaC gnidoC artnaTedoC"Prints "artnaTedoC"No error but nothing will be printedCompile Time Error
Question
Select the correct answerWhat will the output of below given code snippet?#include <stdio.h>void Function (char *S){ if (*S && *S !=' ') { Function(S+1); putchar(*S); }} int main(){ char S1[] = "CodeTantra Coding Castle"; Function(S1); return 0;}OptionsGarbage value will be printedPrints "CodeTantra Coding Castle"Prints "eltsaC gnidoC artnaTedoC"Prints "artnaTedoC"No error but nothing will be printedCompile Time Error
Solution
The correct answer is "Prints "eltsaC gnidoC artnaTedoC"".
Here's why:
The given code is a C program that uses recursion to reverse a string. The function Function is called with the string "CodeTantra Coding Castle".
In the function, it first checks if the string is not empty and the current character is not a space. If these conditions are met, it calls itself with the next character in the string. This continues until it reaches the end of the string.
Then, it starts printing the characters in reverse order as it returns from the recursive calls. The spaces are not printed because the function only prints a character if it is not a space.
So, the output of the program will be the reverse of the string "CodeTantra Coding Castle" without spaces, which is "eltsaC gnidoC artnaTedoC".
Similar Questions
What will be the output of the following code snippet?
Select the correct answerWhat will be the output of the following Python code snippet if x=1?x<<2Options1248
Select the correct answerWhat will be the output of the following Python code snippet?ct = 'code'for i in range(len(ct)): print(ct) ct = 'a'Optionsnone of the mentionedaaaacodecodecodecodea
Select the correct answerWhat is the output of the following code snippet?for (int i = 0; i < 5; i++) { System.out.print(i + " ");}Options0 1 2 3 40 1 2 3Compilation error1 2 3 4 5
What will be the output of the following code?a = "abce" >= "abcdef"print(a)Options: Pick one correct answer from belowTrueFalseBoth A and BNone of the Above
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.