logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings Comments

  • Question
  • What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?
    #include<stdio.h>
    
    int main()
    {
        void fun();
        fun();
        printf("\n");
        return 0;
    }
    void fun()
    {
        char c;
        if((c = getchar())!= '\n')
            fun();
        printf("%c", c);
    }
    


  • Options
  • A. abc abc
  • B. bca
  • C. Infinite loop
  • D. cba

  • Correct Answer
  • cba 

    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


    Strings problems


    Search Results


    • 1. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          static char s[25] = "The cocaine man";
          int i=0;
          char ch;
          ch = s[++i];
          printf("%c", ch);
          ch = s[i++];
          printf("%c", ch);
          ch = i++[s];
          printf("%c", ch);
          ch = ++i[s];
          printf("%c", ch);
          return 0;
      }
      

    • Options
    • A. hhe!
    • B. he c
    • C. The c
    • D. Hhec
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
          int i;
          char *t;
          t = names[3];
          names[3] = names[4];
          names[4] = t;
          for(i=0; i<=4; i++)
              printf("%s,", names[i]);
          return 0;
      }
      

    • Options
    • A. Suresh, Siva, Sona, Baiju, Ritu
    • B. Suresh, Siva, Sona, Ritu, Baiju
    • C. Suresh, Siva, Baiju, Sona, Ritu
    • D. Suresh, Siva, Ritu, Sona, Baiju
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("India", "CURIOUSTAB\n");
          return 0;
      }
      

    • Options
    • A. Error
    • B. India CURIOUSTAB
    • C. India
    • D. CURIOUSTAB
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str1[5], str2[5];
          int i;
          gets(str1);
          gets(str2);
          i = strcmp(str1, str2);
          printf("%d\n", i);
          return 0;
      }
      

    • Options
    • A. Unpredictable integer value
    • B. 0
    • C. -1
    • D. Error
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char str[] = "India\0\CURIOUSTAB\0";
          printf("%s\n", str);
          return 0;
      }
      

    • Options
    • A. CURIOUSTAB
    • B. India
    • C. India CURIOUSTAB
    • D. India\0CURIOUSTAB
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char sentence[80];
          int i;
          printf("Enter a line of text\n");
          gets(sentence);
          for(i=strlen(sentence)-1; i >=0; i--)
              putchar(sentence[i]);
          return 0;
      }
      

    • Options
    • A. The sentence will get printed in same order as it entered
    • B. The sentence will get printed in reverse order
    • C. Half of the sentence will get printed
    • D. None of above
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          printf("%c\n", "abcdefgh"[4]);
          return 0;
      }
      

    • Options
    • A. Error
    • B. d
    • C. e
    • D. abcdefgh
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str[25] = "CuriousTab";
          printf("%s\n", &str+2);
          return 0;
      }
      

    • Options
    • A. Garbage value
    • B. Error
    • C. No output
    • D. diaCURIOUSTAB
    • Discuss
    • 9. What will be the output of the program (Turbo C in 16 bit platform DOS)?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char *str1 = "India";
          char *str2 = "CURIOUSTAB";
          char *str3;
          str3 = strcat(str1, str2);
          printf("%s %s\n", str3, str1);
          return 0;
      }
      

    • Options
    • A. CuriousTab India
    • B. CuriousTab CuriousTab
    • C. India India
    • D. Error
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          char a[] = "\0";
          if(printf("%s", a))
              printf("The string is not empty\n");
          else
              printf("The string is empty\n");
          return 0;
      }
      

    • Options
    • A. The string is not empty
    • B. The string is empty
    • C. No output
    • D. 0
    • Discuss


    Comments

    There are no comments.

Enter a new Comment