Course: Programming with C (SEC)
Code: CASEC101
Functions are the building blocks of a C program, allowing for modularity and code reuse.
main() to perform their specific task.Data is transferred to functions through arguments, which must have specified data types.
Prototypes provide the compiler with necessary information about a function before it is used.
float, double, or char.Storage classes determine the visibility (scope) and lifetime of variables in C.
| Class | Keyword | Scope | Lifetime |
|---|---|---|---|
| Automatic | auto | Inside the block/function. | Function execution duration. |
| External | extern | Global (across files). | Program execution duration. |
| Static | static | Inside the block/function. | Program execution duration (value is retained). |
| Register | register | Inside the block/function. | Function execution duration (stored in CPU register). |
Scope rules define where a variable is accessible within the program.
{} to define blocks of code, allowing for nested scopes where variables can be protected or shared.stdio.h).Recursion occurs when a function calls itself to solve a smaller version of the same problem.
The preprocessor handles directives that begin with # before the actual compilation starts.
#include), macro expansion (#define), and conditional compilation.static keyword when a variable needs to retain its value between function calls.Q: What is a recursive function?
A: It is a function that calls itself to solve a sub-problem.
Q: Why are header files used?
A: To include function prototypes and declarations so that functions defined in other files can be used correctly.