Binary File Modes in C

During programming binary file can be opened for different purposes i.e. reading, writing or both. This is specified by using file modes. Different binary file modes in C programming are tabulated below:

ModesPurpose
rbOpen binary file for reading only. The file must already exist.
wbOpen binary file for writing only. If the file specified already exists, its contents will be destroyed. If it does not exist it will be created.
abOpen binary file for appending (i.e. adding data to the end of existing file). If it does not exist it will be created.
rb+/r+bOpen binary file for both reading and writing. The file must already exist.
wb+/w+bOpen binary file for both reading and writing. If the file exists, its content will be overwritten. If it does not exist it will be created.
ab+/a+bOpen binary file for both reading and appending. If a file does not exist it will be created.