logo

CuriousTab

CuriousTab

Discussion


Home C Programming Library Functions Comments

  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        int i;
        char c;
        for(i=1; i<=5; i++)
        {
            scanf("%c", &c); /* given input is 'a' */
            printf("%c", c);
            ungetc(c, stdin);
        }
        return 0;
    }
    


  • Options
  • A. aaaa
  • B. aaaaa
  • C. Garbage value.
  • D. Error in ungetc statement.

  • Correct Answer
  • aaaaa 

    Explanation
    for(i=1; i<=5; i++) Here the for loop runs 5 times.

    Loop 1:
    scanf("%c", &c); Here we give 'a' as input.
    printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement.
    ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

    Loop 2:
    Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function.
    printf("%c", c); Now variable c = 'a'. So it prints the character 'a'.
    ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

    This above process will be repeated in Loop 3, Loop 4, Loop 5.


    Library Functions problems


    Search Results


    • 1. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          char c;
          for(i=1; i<=5; i++)
          {
              scanf("%c", &c); /* given input is 'b' */
              ungetc(c, stdout);
              printf("%c", c);
              ungetc(c, stdin);
          }
          return 0;
      }
      

    • Options
    • A. bbbb
    • B. bbbbb
    • C. b
    • D. Error in ungetc statement.
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          i = printf("How r u\n");
          i = printf("%d\n", i);
          printf("%d\n", i);
          return 0;
      }
      

    • Options
    • A. How r u
      7
      2
    • B. How r u
      8
      2
    • C. How r u
      1
      1
    • D. Error: cannot assign printf to variable
    • Discuss
    • 3. What will function gcvt() do?

    • Options
    • A. Convert vector to integer value
    • B. Convert floating-point number to a string
    • C. Convert 2D array in to 1D array.
    • D. Covert multi Dimensional array to 1D array
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      #include<math.h>
      
      int main()
      {
          float i = 2.5;
          printf("%f, %d", floor(i), ceil(i));
          return 0;
      }
      

    • Options
    • A. 2, 3
    • B. 2.000000, 3
    • C. 2.000000, 0
    • D. 2, 0
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          i = scanf("%d %d", &i, &i);
          printf("%d\n", i);
          return 0;
      }
      

    • Options
    • A. 1
    • B. 2
    • C. Garbage value
    • D. Error: cannot assign scanf to variable
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      int main()
      {
          char *i = "55.555";
          int result1 = 10;
          float result2 = 11.111;
          result1 = result1+atoi(i);
          result2 = result2+atof(i);
          printf("%d, %f", result1, result2);
          return 0;
      }
      

    • Options
    • A. 55, 55.555
    • B. 66, 66.666600
    • C. 65, 66.666000
    • D. 55, 55
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int x, y, z;
          x=y=z=1;
          z = ++x || ++y && ++z;
          printf("x=%d, y=%d, z=%d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. x=2, y=1, z=1
    • B. x=2, y=2, z=1
    • C. x=2, y=2, z=2
    • D. x=1, y=2, z=1
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          char ch;
          if(ch = printf(""))
              printf("It matters\n");
          else
              printf("It doesn't matters\n");
          return 0;
      }
      

    • Options
    • A. It matters
    • B. It doesn't matters
    • C. matters
    • D. No output
    • Discuss
    • 9. What will be the output of the program, if a short int is 2 bytes wide?
      #include<stdio.h>
      int main()
      {
          short int i = 0;
          for(i<=5 && i>=-1; ++i; i>0)
              printf("%u,", i);
          return 0;
      }
      

    • Options
    • A. 1 ... 65535
    • B. Expression syntax error
    • C. No output
    • D. 0, 1, 2, 3, 4, 5
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          unsigned int i = 65536; /* Assume 2 byte integer*/
          while(i != 0)
              printf("%d",++i);
          printf("\n");
          return 0;
      }
      

    • Options
    • A. Infinite loop
    • B. 0 1 2 ... 65535
    • C. 0 1 2 ... 32767 - 32766 -32765 -1 0
    • D. No output
    • Discuss


    Comments

    There are no comments.

Enter a new Comment