NTA UGC NET JUNE-2023 Paper-2
November 11, 2023Software-Engineering
November 11, 2023Question 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.
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.
?1 is getchar() ! = ‘\n’
?2 is getchar(c);
?2 is getchar(c);
?1 is (c = getchar()); ! = ‘\n’
?2 is getchar(c);
?2 is getchar(c);
?1 is c! = ‘\n’
?2 is putchar(c);
?2 is putchar(c);
?1 is (c = getchar()) ! = ‘\n’
?2 is putchar(c);
?2 is putchar(c);
Subscribe
Login
0 Comments