Choose the correct option to fill $?1$ and $?2$ so that the program below prints an input string in reverse order. Assume that the input string is terminated by a new line character.
$?1$ is $(getchar() != ’\setminus n’)$
$?1$ is $((c = getchar() ) !=’\setminus n’)$
$?2$ is $getchar(c);$
$?1$ is $(c != ’\setminus n’)$
$?2$ is $putchar(c);$
$?1$ is $((c = getchar() ) != ’\setminus n’)$
Here, we are using the '$=$' operator which has less priority than '$!=$' operator. So $(c=getchar())$ has to be in brackets and after reversing the string we use function $putchar(c)$ for printing the character.
So, option (D) is the right answer.
@ Swati Rauniyar
u mean after printing stack will remove that character from the stack, so there will be no need of pointer.
$getchar()$ - reads a single character at a time from the $stdin$.
$putchar(c)$ - writes a character specified by the argument to $stdout$.
As getchar() and putchar() both are needed to read the string and print its reverse and only option D contains both the function. D is the answer.
Now coming to the code.
$reverse(void)$ is calling itself recursively. when \n is encountered $putchar()$ gets executed and prints the last character and then the function returns to its previous call and prints last 2nd character and so on.