Which of the following is the correct way to open a file "PRI.EXE" in read binary mode?

This question was previously asked in
Beltron Programmer 1 Oct 2023 Official Paper
View all BELTRON Programmer Papers >
  1. FILE *fp = fopen("PR1.EXE", read-binary-mode);
  2. FILE *fp = fopen("PR1.EXE", "rb");
  3. FILE *fp = fopen("PR1.EXE", O_READ | O_BINARY);
  4. FILE *fp = fopen("PR1.EXE", READ | BINARY);

Answer (Detailed Solution Below)

Option 2 : FILE *fp = fopen("PR1.EXE", "rb");
Free
Beltron Programmer Mock Test
0.8 K Users
20 Questions 20 Marks 24 Mins

Detailed Solution

Download Solution PDF

The correct answer is Option 2) FILE *fp = fopen("PR1.EXE", "rb");.

Key Points

  • The fopen() function in C is used to open files.
  • The second parameter specifies the mode in which the file should be opened.
  • "rb" stands for read binary mode:
    • r: open for reading
    • b: treat the file as binary, not text
  • Therefore, the correct syntax to open a file named PR1.EXE in read-binary mode is:
    FILE *fp = fopen("PR1.EXE", "rb");

Additional Information

  • Option 1 – Incorrect: read-binary-mode is not valid C syntax.
  • Option 3 – Incorrect: O_READ | O_BINARY is used in open() system call (low-level I/O), not fopen().
  • Option 4 – Incorrect: READ | BINARY is invalid and not part of standard C I/O mode strings.
  • Other common fopen modes:
    • "r": read (text)
    • "w": write (text, truncates if exists)
    • "a": append (text)
    • "rb", "wb", "ab": binary equivalents
Latest BELTRON Programmer Updates

Last updated on Nov 25, 2024

-> BELTRON Programmer 2024 Notification has been released on the official website.

-> The Bihar State Electronics Development Corporation Limited (BELTRON) has announced a recruitment drive for Programmer positions on a contractual basis.

-> Specific vacancy details will be shared separately.

-> Interested candidates can apply online from November 11, 2024, to December 10, 2024.

-> The Minimum age of the candidates should be 21 years and maximum age should be 59 year of age. 

Get Free Access Now
Hot Links: mpl teen patti dhani teen patti teen patti joy 51 bonus