Course: Programming with C
Code: CADSM101
A function is a self-contained block of code that performs a specific task. Using functions helps in modularizing code and promoting reusability.
main(), to execute their tasks.Functions can receive data through arguments. In C, you must specify the data type for each argument passed to a function.
A Function Prototype tells the compiler about the function's name, return type, and parameters before the actual definition is provided.
int, such as float, double, or char.Storage classes define the scope, visibility, and lifetime of variables within a C program.
| Storage Class | Keyword | Location | |
|---|---|---|---|
| Automatic | auto | Stack (Memory) | Local to the block. |
| External | extern | Data Segment | Global; persists for the entire program. |
| Static | static | Data Segment | Value persists between function calls. |
| Register | register | CPU Register | Fast access; local to the block. |
The scope refers to the region of the program where a variable is accessible.
{}, where inner blocks can access outer variables (unless shadowed).Recursion is a technique where a function calls itself to solve smaller instances of the same problem.
Example: Factorial of n is n * Factorial(n-1).
The preprocessor processes the source code before it is passed to the compiler.
.h (like stdio.h) containing function declarations and macros.#define.Q: What is a function prototype?
A: It is a declaration of the function that informs the compiler about the return type and arguments before the function is called.
Q: What is the difference between auto and static variables?
A: auto variables are destroyed when the function ends, while static variables keep their value for the next call.