File Handling, Preprocessor, Compilation, and Makefiles Flashcards
(40 cards)
Fill in the blank: To create a binary file for writing, use mode _______.
wb
What is the action of the function fputs()?
Write a string.
What does fprintf() do?
Writes to a file like printf().
What is the purpose of the function fseek()?
Jump to a specific position in a file.
What is the role of errno in error handling?
Global variable to check errors.
What are the three standard streams in C?
stdin, stdout, stderr
What does stdout represent?
Standard output (console).
What is the result of the command ./myprogram > output.txt 2> errors.txt?
Saves stdout in output.txt and stderr in errors.txt.
What happens when you reach the end of a file (EOF)?
Stops reading.
What is the summary takeaway regarding file operations?
Always check if fopen() worked before reading/writing.
True or False: The function remove() is used to delete a file.
True.
What is the C Preprocessor?
Preprocessor expands macros, includes headers, removes comments, and modifies source code before compilation.
What does the directive #include <file> do?</file>
Includes a system header file.
What does the directive #include “file” do?
Includes a user-defined header file.
What is the purpose of #define MACRO?
Defines a macro (a shortcut for values or code).
What happens when #ifdef MACRO is used?
Compiles code only if a macro is defined.
What does #ifndef MACRO do?
Compiles code only if a macro is NOT defined.
What is the function of #undef MACRO?
Undefines a macro.
What does the #pragma directive provide?
Compiler-specific instructions (rarely used).
What are system headers and how are they included?
System headers are included using angle brackets < >, e.g., #include <stdio.h>.</stdio.h>
What are user-defined headers and how are they included?
User-defined headers are included using quotes “ “, e.g., #include “myfile.h”.
What does #define PI 3.14159 accomplish?
Replaces every PI in the code with 3.14159.
What is a common pitfall when using macros?
Not using parentheses can lead to unexpected results.
How can the MAX macro be defined correctly?
define MAX(a, b) ((a) > (b) ? (a) : (b))