-
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 newline character.
void recerse (void){
int c;
if (?1) reverse ();
?2
}
main () {
printf(“Enter Text”); printf(“/n”);
reverse (); printf(“/n”)
-
- ?1 is (getchar ()! = ‘\n’)
?2 is getchar (c);
- ?1 is (c = getchar ())! = ‘\n’)
?2 is getchar (c);
- ?1 is (c! = ‘\n’)
?2 is putchar (c);
- ?1 is (c = getchar ())! = ‘\n’)
?2 is putchar (c);
- ?1 is (getchar ()! = ‘\n’)
Correct Option: D
The option chosen is
?1 is ((c = getchar ())! = ‘\n’)
?2 is putchar (c);
Because the operator ‘1=’ has higher priority than ‘=’ operator so according to this C = getchar () should be contained in brackets and when the string is reversed then the function putchar (c) is used so that the characters can be printed.