Modify array using function (pointer) Dry Run in C

Modify array 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.

Modify array using function (pointer) Program Code

#include <stdio.h>

void multiplyArray(int *arr, int size, int multiplier) {
    int i;
    for(i = 0; i < size; i++) {
        arr[i] = arr[i] * multiplier;
        // Equivalent to: *(arr + i) = *(arr + i) * multiplier;
    }
}

void addToArray(int *arr, int size, int value) {
    int *end = arr + size;
    while(arr < end) {
        *arr += value;
        arr++;
    }
}

void printArray(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
}

int main() {
    int numbers[] = {1, 2, 3, 4, 5, 6, 7, 8};
    int size = sizeof(numbers)/sizeof(numbers[0]);
    
    printf("Original array: ");
    printArray(numbers, size);
    
    multiplyArray(numbers, size, 2);
    printf("After multiplying by 2: ");
    printArray(numbers, size);
    
    addToArray(numbers, size, 5);
    printf("After adding 5: ");
    printArray(numbers, size);
    
    printf("\nNote: Array was modified directly - no copy made!\n");
    
    return 0;
}

View the complete Pointersfunctions programs page.

Program Console Modify array using function (pointer) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.