[Solved] How to pass array “by reference” in C? [duplicate]


I do not judge your algorithm or C conventions, friends who comment on your problem are totally right. But if you still do it in this way you can use this approach.

#include <stdio.h>
#include <string.h>

void removeFirstAndLastChar(char* string) {
    memmove(string,string+1,strlen(string));
    string[strlen(string)-1]=0;
}

int main(void) {
    char title[] = "ABC";
    removeFirstAndLastChar(title);
    printf("%s", title);
    // Expected output: B
    return 0;
}

solved How to pass array “by reference” in C? [duplicate]