Unit V: Arrays, Functions, and Pointers

Table of Contents

1. One-dimensional Arrays

An Array is a fixed-size, sequenced collection of elements of the same data type.


2. User-defined Functions

User-defined functions are subprograms created by the programmer to perform specific tasks, promoting modularity and code reuse.


3. Categories of Functions

Based on the presence of arguments and return values, functions are categorized into four types:

Category Description
No Arguments & No Return Values The function simply performs a task without needing input or sending output back.
Arguments but No Return Values Data is sent to the function, but results are printed or used within the function itself.
Arguments with Return Values The most common type; it takes input data, processes it, and returns a result.
No Arguments but Returns a Value Useful for functions that read data from a keyboard or file and return it to the caller.

Passing Arrays to Functions: Entire arrays can be passed to functions as arguments to perform operations like searching or sorting.


4. Recursion

Recursion is a programming technique where a function calls itself directly or indirectly to solve a problem.

Essential Rule: A recursive function must have a termination condition (base case) to prevent an infinite loop.

5. Introduction to Pointers

Pointers are variables that store the memory address of another variable.

Exam Tips


Frequently Asked Questions

Q1: What is the benefit of passing an array to a function?
It allows the function to work on large sets of data without copying the entire data set, as only the address of the first element is usually passed.

Q2: Why is recursion sometimes slower than iteration?
Recursion involves repeated function calls, which add overhead to the system stack, whereas iteration (loops) generally uses less memory and processing time.