0Pricing
C Academy · Lesson

Pointer Arrays and Function Pointers

Understand the concept of arrays of pointers and how function pointers are used for callbacks and efficient program execution.

Pointer Arrays and Function Pointers is a free C Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Pointer Arrays and Function Pointers

Pointers can be used in arrays to store multiple memory addresses, and function pointers allow functions to be passed as arguments.

In this lesson, you will learn:

  • How to declare and use pointer arrays.
  • How function pointers work.
  • How function pointers are used for callbacks.
Pointer Arrays and Function Pointers — illustration 1

2

What is an Array of Pointers?

An array of pointers is an array where each element is a pointer.

Example:

int *arr[5];

This array can store 5 integer pointers.

3

Example: Array of Pointers

This program demonstrates an array of pointers.

#include <stdio.h>

int main() {
    int a = 10, b = 20, c = 30;
    int *arr[3] = {&a, &b, &c};
    for (int i = 0; i < 3; i++) {
        printf("Value: %d\n", *arr[i]);
    }
    return 0;
}

4

What is a Function Pointer?

A function pointer stores the address of a function and allows it to be called dynamically.

Example declaration:

int (*funcPtr)(int, int);

This defines a pointer to a function that takes two integers and returns an integer.

5

Example: Function Pointer

This program demonstrates how to use a function pointer.

#include <stdio.h>

int add(int a, int b) {
    return a + b;
}

int main() {
    int (*funcPtr)(int, int) = add;
    printf("Sum: %d\n", funcPtr(5, 10));
    return 0;
}

6

Passing a Function Pointer to Another Function

Function pointers can be passed as arguments.

Example:

void execute(int (*operation)(int, int)) { }

This function accepts a function pointer as a parameter.

7

Example: Passing Function Pointer as Argument

This program demonstrates how to pass a function pointer as a parameter.

#include <stdio.h>

int multiply(int a, int b) {
    return a * b;
}

void execute(int (*operation)(int, int), int x, int y) {
    printf("Result: %d\n", operation(x, y));
}

int main() {
    execute(multiply, 4, 5);
    return 0;
}

8

9

Use Cases of Function Pointers

Function pointers are used for:

  • Callbacks in event-driven programming.
  • Sorting functions (e.g., qsort()).
  • Implementing state machines.

10

Summary

In this lesson, you learned:

  • How to use arrays of pointers.
  • How to declare and use function pointers.
  • How to pass function pointers as arguments.

Next, we will explore structures, unions, and enumerations in C!

Pointer Arrays and Function Pointers — illustration 10

Frequently asked questions

Is the “Pointer Arrays and Function Pointers” lesson free?

Yes — the full text of “Pointer Arrays and Function Pointers” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.

What will I learn in “Pointer Arrays and Function Pointers”?

Understand the concept of arrays of pointers and how function pointers are used for callbacks and efficient program execution. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Pointer Arrays and Function Pointers” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Pointers
  2. Dynamic Memory Allocation
  3. Pointer Arrays and Function Pointers
← Back to C Academy