Unit II: Functions and Program Structure

Course: Programming with C (SEC)
Code: CASEC101

Table of Contents

Defining and Accessing Functions

Functions are the building blocks of a C program, allowing for modularity and code reuse.

Passing Arguments and Data Types

Data is transferred to functions through arguments, which must have specified data types.

Function Prototypes and Return Types

Prototypes provide the compiler with necessary information about a function before it is used.

Storage Classes

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 and Block Structure

Scope rules define where a variable is accessible within the program.

Recursion in C

Recursion occurs when a function calls itself to solve a smaller version of the same problem.

The C Preprocessor

The preprocessor handles directives that begin with # before the actual compilation starts.

Exam Focus & Tips


Frequently Asked Questions

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.