Why should C code be organized into functions?
A
To increase code length
C
To improve readability and reuse
Analysis & Theory
Functions make code modular, reusable, and easier to test and maintain.
What is the purpose of a header file (`.h`) in C?
A
To store the main function
B
To include precompiled code
C
To declare function prototypes and definitions
D
To store error messages
Analysis & Theory
Header files are used for function declarations, macros, constants, and structure definitions.
Which directive is used to include a header file?
Analysis & Theory
`#include` adds the content of a header or source file into the current file during preprocessing.
What is the benefit of separating `.c` and `.h` files?
C
Encourages modular programming
D
Compiles into a single file
Analysis & Theory
Separation promotes modular design, clearer interfaces, and better organization.
What does the `static` keyword do to a function in a `.c` file?
C
Limits visibility to the current file
Analysis & Theory
`static` restricts function or variable scope to the file it's declared in (internal linkage).
Which of the following is a good naming convention in C?
A
Function names in UPPERCASE
B
Using short or single-letter names
C
Descriptive, lowercase_with_underscores
Analysis & Theory
Use meaningful, consistent naming with underscores (e.g., `calculate_sum`).
Which file should contain the `main()` function?
C
A single `.c` file (e.g., main.c)
Analysis & Theory
Only one `.c` file (commonly `main.c`) should contain the `main()` function.
Why should global variables be avoided when organizing code?
A
They slow down the program
B
They increase compile time
C
They make code harder to understand and maintain
D
They are stored in heap
Analysis & Theory
Global variables reduce modularity and increase risk of unintended side effects.
Which of the following improves **code reusability**?
A
Writing large functions
C
Creating generic utility functions
Analysis & Theory
Well-defined utility functions can be reused across multiple programs or modules.
What is a common technique to avoid multiple inclusion of a header file?
B
#ifndef HEADER_H ... #endif
Analysis & Theory
`#ifndef`, `#define`, and `#endif` are used to create header guards and prevent multiple inclusion.