C Programming Multiple Choice Questions and Answers on File Accessing for Freshers

1. Which of the following fopen statements are illegal?

a) fp = fopen(“abc.txt”, “r”);
b) fp = fopen(“/home/user1/abc.txt”, “w”);
c) fp = fopen(“abc”, “w”);
d) none of the mentioned
Answer: d
2. What does the following segment of code do?
    fprintf(fp, “Copying!”);

a) It writes “Copying!” into the file pointed by fp
b) It reads “Copying!” from the file and prints on display
c) It writes as well as reads “Copying!” to and from the file and prints it
d) None of the mentioned
Answer: a
3. FILE reserved word is

a) A structure tag declared in stdio.h
b) One of the basic datatypes in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h
Answer: d
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp = stdin;
  5.         int n;
  6.         fprintf(fp, "%d", 45);
  7.     }
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard
Answer: c
5. What is the output of this C code?
  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         FILE *fp = stdout;
  6.         int n;
  7.         fprintf(fp, "%d", 45);
  8.     }
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard
Answer: b
6. stdout, stdin and stderr are

a) File pointers
b) File desciptors
c) Streams
d) Structure
Answer: a
7. Which of the following statements about stdout and stderr are true?

a) Same
b) Both connected to screen always
c) Both connected to screen by default
d) stdout is line buffered but stderr is unbuffered
Answer: c
8. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp = stdout;
  5.         int n;
  6.         fprintf(fp, "%d ", 45);
  7.         fprintf(stderr, "%d ", 65);
  8.         return 0;
  9.     }
a) 45 65
b) 65 45
c) 65
d) Compilation error
Answer: b
9. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp = stdout;
  5.         int n;
  6.         fprintf(fp, "%d\n ", 45);
  7.         fprintf(stderr, "%d ", 65);
  8.         return 0;
  9.     }
a) 45 65
b) 65 45
c) 65
d) Compilation error
Answer: a
10. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp = stdout;
  5.         int n;
  6.         fprintf(fp, "%d ", 45);
  7.         fflush(stdout);
  8.         fprintf(stderr, "%d", 65);
  9.         return 0;
  10.     }
a) 45 65
b) 65 45
c) 45
d) Compilation error
Answer: a

11. The first and second arguments of fopen are

a) A character string containing the name of the file & the second argument is the mode
b) A character string containing the name of the user & the second argument is the mode
c) A character string containing file poniter & the second argument is the mode
d) None of the mentioned
Answer: a
12. For binary files, a ___ must be appended to the mode string.

a) Nothing
b) “b”
c) “binary”
d) “01”
Answer: b
13. If there is any error while opening a file, fopen will return

a) Nothing
b) EOF
c) NULL
d) Depends on compiler
Answer: c
14. Which is true about getc.getc returns?

a) The next character from the stream is not referred by file pointer
b) EOF for end of file or error
c) Nothing
d) None of the mentioned
Answer: b
15. When a C program is started, O.S environment is responsible for opening file and providing     pointer for that file?

a) Standard input
b) Standard output
c) Standard error
d) All of the menitoned
Answer: d
16. FILE is of type ______

a) int type
b) char * type
c) struct type
d) None of the mentioned
Answer: c
17. What is the meant by ‘a’ in the following operation?
    fp = fopen(“Random.txt”, “a”);

a) Attach
b) Append
c) Apprehend
d) Add
Answer: b
18. Which of the following mode argument is used to truncate?

a) a
b) f
c) w
d) t
Answer: c
19. Which type of files can’t be opened using fopen()?

a) .txt
b) .bin
c) .c
d) none of the mentioned
Answer: d

Related

Multiple Choice Questions 225758623070328218

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