Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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. ?1 is (getchar ()! = ‘\n’)
      ?2 is getchar (c);

    2. ?1 is (c = getchar ())! = ‘\n’)
      ?2 is getchar (c);

    3. ?1 is (c! = ‘\n’)
      ?2 is putchar (c);
    4. ?1 is (c = getchar ())! = ‘\n’)
      ?2 is putchar (c);
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.



Your comments will be displayed only after manual approval.