Home / C Programming / Strings :: Discussion

Discussion :: Strings

  1. What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?

    
    
    #include 
     int main() 
      {    
         void fun();   
         fun();     
         printf("\n");   
         return 0;
      }
      void fun() 
      {     
          char c;    
          if((c = getchar())!= '\n')                                           
          fun();   
          printf("%c", c); 
     } 
    

  2. A.

    abc abc

    B.

    bca

    C.

    Infinite loop

    D.

    cba

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Step 1: void fun(); This is the prototype for the function fun().

    Step 2: fun(); The function fun() is called here.

    The function fun() gets a character input and the input is terminated by an enter key(New line character). It prints the given character in the reverse order.

    The given input characters are "abc"

    Output: cba


Be The First To Comment