Basic function pointer example Dry Run in C

Basic function pointer example is an interactive C dry run visualizer from the Pointersfunctions programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Basic function pointer example Program Code

#include <stdio.h>

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

int subtract(int a, int b) {
    return a - b;
}

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

int main() {
    // Declare a function pointer that can point to functions taking two ints and returning int
    int (*operation)(int, int);
    
    // Assign function pointer to add function
    operation = add;
    printf("add(10, 5) via pointer = %d\n", operation(10, 5));
    
    // Assign to subtract
    operation = subtract;
    printf("subtract(10, 5) via pointer = %d\n", operation(10, 5));
    
    // Assign to multiply
    operation = multiply;
    printf("multiply(10, 5) via pointer = %d\n", operation(10, 5));
    
    // Alternative syntax - using address-of operator
    operation = &add;
    printf("\nWith & operator: (*operation)(10,5) = %d\n", (*operation)(10,5));
    
    // Print function addresses
    printf("\nFunction addresses:\n");
    printf("add function address: %p\n", add);
    printf("subtract function address: %p\n", subtract);
    printf("multiply function address: %p\n", multiply);
    
    return 0;
}

View the complete Pointersfunctions programs page.

Program Console Basic function pointer example Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.