Call function using function pointer Dry Run in C

Call function using function pointer 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.

Call function using function pointer Program Code

#include <stdio.h>

void greetEnglish() {
    printf("Hello!\n");
}

void greetSpanish() {
    printf("Hola!\n");
}

void greetFrench() {
    printf("Bonjour!\n");
}

void greetGerman() {
    printf("Hallo!\n");
}

void executeGreeting(void (*greetFunc)()) {
    printf("Executing: ");
    greetFunc();
}

int main() {
    int i;
    int choice;
    // Array of function pointers
    void (*greetings[4])() = {greetEnglish, greetSpanish, greetFrench, greetGerman};
    
    printf("Calling functions directly from array:\n");
    for(i = 0; i < 4; i++) {
        greetings[i]();
    }
    
    printf("\nPassing function pointers as arguments:\n");
    executeGreeting(greetEnglish);
    executeGreeting(greetSpanish);
    executeGreeting(greetFrench);
    executeGreeting(greetGerman);
    
    // Dynamic selection based on input
    printf("\nSelect language (0-3): ");
    scanf("%d", &choice);
    
    if(choice >= 0 && choice < 4) {
        greetings[choice]();
    } else {
        printf("Invalid choice\n");
    }
    
    return 0;
}

View the complete Pointersfunctions programs page.

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