pointers-memory · beginner · ~15 min

String length by pointer

Measure a string with two pointer positions.

Challenge

Implement int str_len_ptr(const char *s) returning the length using pointer subtraction (advance to the NUL, then subtract).

Starter code

int str_len_ptr(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.