Input & Output


  1. What will be the output of the following C code if 2 character is typed by the user?
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    char line[25];
    fgets(line, 25, stdin);
    printf("%d\n", line[2]);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    64


  1. What will be the output of the following C code?
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    char line[25];
    FILE *fp;
    fp = fopen("file.txt", "r");
    while (fgets(line, 25, fp))
    fputs(line, stdout);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Segmentation fault



  1. gets() does the following when it reads from stdin.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Deletes the terminating ‘n’


  1. fputs() function writes a string to a file that only ends with a newline.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    False



  1. The syntax of fgets is char *fgets(char *line, int maxline, FILE *fp). Which is true for fgets?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Both On end of file or error it returns NULL & returns line on success