NTA UGC NET JUNE-2023 Paper-2
November 11, 2023
Software-Engineering
November 11, 2023
NTA UGC NET JUNE-2023 Paper-2
November 11, 2023
Software-Engineering
November 11, 2023

Question 11188 – Programming

Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is terminated by a new line character.

#include 
void wrt_it (void);
int main (void)
{
    printf("Enter Text"); 
    printf ("n");
    wrt_ it();
    printf ("n");
    return 0;
}
void wrt_it (void)
{
    int c;
    if (?1)
        wrt_it();
    ?2
} 

Correct Answer: D

Question 5 Explanation: 
getchar( ) = reads a single character at a time from the stdin.
putchar( ) = writes a character specified by the argument to stdout.
As getchar( ) and putchar( ), both are needed to read the string and prints its reverse and only option (D) contains both the function. (D) is the answer.
Now coming to the code, wrt_id(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.
A
?1 is getchar() ! = ‘\n’
?2 is getchar(c);
B
?1 is (c = getchar()); ! = ‘\n’
?2 is getchar(c);
C
?1 is c! = ‘\n’
?2 is putchar(c);
D
?1 is (c = getchar()) ! = ‘\n’
?2 is putchar(c);
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!