C Programming Questions and Answers – File Access – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “File Access – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

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
View Answer

Answer: d
Explanation: None.

2. What does the following segment of C code do?

advertisement
advertisement
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
View Answer

Answer: a
Explanation: None.
advertisement

3. What is FILE reserved word?
a) A structure tag declared in stdio.h
b) One of the basic data types in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h
View Answer

Answer: d
Explanation: None.

4. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.
advertisement

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  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
View Answer

Answer: b
Explanation: None.

6. stdout, stdin and stderr are ________
a) File pointers
b) File descriptors
c) Streams
d) Structure
View Answer

Answer: a
Explanation: None.

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
View Answer

Answer: c
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

9. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

10. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.