C Programming Multiple Choice Questions and Answers on Line Input & Output in Files for Freshers

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

a) returns line on success
b) On end of file or error it returns NULL
c) Nothing
d) Both returns line on success & On end of file or error it returns NULL
Answer: d
2. fputs function writes a string to a file that only ends with a newline.

a) true
b) false
c) Depends on the standard
d) Depends on the compiler
Answer: b
3. What is the output of this C code?
  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char line[3];
  6.         fgets(line, 3, stdin);
  7.         printf("%d\n", strlen(line));
  8.         return 0;
  9.     }
a) 3
b) 1
c) Any length since line did not end with null character
d) Depends on the standard
Answer: b
4. What is the output of this C code?
  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char line[3];
  6.         FILE *fp;
  7.         fp = fopen("newfile.txt", "r");
  8.         while (fgets(line, 3, fp))
  9.         fputs(line, stdout);
  10.         return 0;
  11.     }
a) Compilation error
b) Infinite loop
c) Segmentation fault
d) No.of lines present in file newfile
Answer: c
5. What is the output of this C code if 2 character is typed by the user?
  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char line[3];
  6.         fgets(line, 3, stdin);
  7.         printf("%d\n", line[2]);
  8.         return 0;
  9.     }
a) Compilation error
b) Undefined behaviour
c) 0
d) 10(ascii value of newline character)
Answer: c
6. fputs adds newline character

a) True
b) False
c) Depends on the standard
d) Undefined behaviour
Answer: b
7. puts function adds newline character

a) True
b) False
c) Depends on the standard
d) Undefined behaviour
Answer: a
8. gets function checks overflow run

a) True
b) False
c) Depends on the standard
d) Depends on the compiler
Answer: b
9. puts does the following when it writes to stdout

a) Deletes everything
b) Adds ‘t’ to the line written
c) Deletes the terminating ‘n’
d) Adds ‘n’ to the line written
Answer: d
10. What is the size of array “line” used in fgets(line, maxline, *fp) function?

a) maxline – 1
b) maxline
c) maxline + 1
d) Size is dynamic
Answer: b
11. The following function
    int fputs(char *line, FILE *fp)
    returns EOF when:

a) ‘�’ character of array line is encountered
b) ‘n’ character in array line is encountered
c) ‘t’ character in array line is encountered
d) When an error occurs
Answer: d
12. Identify X library function for line input and output?
  1.     #include 
  2.     int X(char *s, FILE *iop)
  3.     {
  4.         int c;
  5.         while (c = *s++)
  6.         putc(c, iop);
  7.         return ferror(iop) ? EOF : 0;
  8.     }
a) getc
b) putc
c) fgets
d) fputs
Answer: d
13. Which function has a return type as char pointer?

a) getline
b) fputs
c) fgets
d) All of the mentioned
Answer: c
14. Which of the following is the right declaration for fgets inside the library?

a) int *fgets(char *line, int maxline, FILE *fp);
b) char *fgets(char *line, int maxline, FILE *fp);
c) char *fgets(char *line, FILE *fp);
d) int *fgets(char *line, FILE *fp);
Answer: b
15. Which is true about fputs.fputs returns?

a) EOF if an error occurs
b) Non-negative if no error
c) EOF if an error occurs & Non-negative if no error
d) None of the mentioned
Answer: c
16. gets and puts operate on

a) stdin and stdout
b) files
c) stderr
d) nothing
Answer: a
17. gets does the following when it reads from stdin

a) Deletes the ‘t’
b) Puts adds it.
c) Deletes the terminating ‘n’
d) Nothing
Answer: c

Related

Multiple Choice Questions 8643679654943512833

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item