File Handling, Preprocessor, Compilation, and Makefiles Flashcards

(40 cards)

1
Q

Fill in the blank: To create a binary file for writing, use mode _______.

A

wb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the action of the function fputs()?

A

Write a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does fprintf() do?

A

Writes to a file like printf().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the function fseek()?

A

Jump to a specific position in a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of errno in error handling?

A

Global variable to check errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the three standard streams in C?

A

stdin, stdout, stderr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does stdout represent?

A

Standard output (console).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the result of the command ./myprogram > output.txt 2> errors.txt?

A

Saves stdout in output.txt and stderr in errors.txt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when you reach the end of a file (EOF)?

A

Stops reading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the summary takeaway regarding file operations?

A

Always check if fopen() worked before reading/writing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False: The function remove() is used to delete a file.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the C Preprocessor?

A

Preprocessor expands macros, includes headers, removes comments, and modifies source code before compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the directive #include <file> do?</file>

A

Includes a system header file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the directive #include “file” do?

A

Includes a user-defined header file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of #define MACRO?

A

Defines a macro (a shortcut for values or code).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens when #ifdef MACRO is used?

A

Compiles code only if a macro is defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does #ifndef MACRO do?

A

Compiles code only if a macro is NOT defined.

18
Q

What is the function of #undef MACRO?

A

Undefines a macro.

19
Q

What does the #pragma directive provide?

A

Compiler-specific instructions (rarely used).

20
Q

What are system headers and how are they included?

A

System headers are included using angle brackets < >, e.g., #include <stdio.h>.</stdio.h>

21
Q

What are user-defined headers and how are they included?

A

User-defined headers are included using quotes “ “, e.g., #include “myfile.h”.

22
Q

What does #define PI 3.14159 accomplish?

A

Replaces every PI in the code with 3.14159.

23
Q

What is a common pitfall when using macros?

A

Not using parentheses can lead to unexpected results.

24
Q

How can the MAX macro be defined correctly?

A

define MAX(a, b) ((a) > (b) ? (a) : (b))

25
What does stringifying macros do?
Converts macro arguments into strings.
26
What is the benefit of structuring code?
Makes code easier to read, allows reusability, and improves debugging and maintainability.
27
What are the components of a structured project?
* myProgram.c (Main Program) * myProgram.h (Header File) * stack.c (Stack Implementation) * stack.h (Stack Function Declarations)
28
What do header files contain?
Function declarations and constants.
29
What do source files contain?
Function definitions.
30
What is the purpose of #ifndef STACK_H?
Prevents multiple inclusions (include guards).
31
What are the three stages of compilation?
* Preprocessing * Compilation * Linking
32
What command compiles source files separately?
gcc -c stack.c -o stack.o
33
What is the command to link object files?
gcc stack.o myProgram.o -o myProgram
34
What is the purpose of a Makefile?
Saves time when recompiling large projects, tracks dependencies, and reduces manual errors.
35
What command is used to build a project using a Makefile?
make
36
What is a library in C?
A collection of precompiled functions that can be used in multiple projects.
37
What is the difference between a static library and a shared library?
* Static Library (.a): Linked at compile time (larger executable) * Shared Library (.so): Linked at runtime (smaller executable)
38
What command links the math library?
gcc myMaths.c -lm -o myMaths
39
What does the -lm flag do?
Tells GCC to link the math library.
40
What does the preprocessor do?
Expands macros, includes headers, and modifies code.