![]() |
VOOZH | about |
Pointer Arithmetic is a technique in C that allows manipulation of memory addresses. We can also manipulate arrays using pointer arithmetic as the arrays are nothing but contiguous memory block.
Strings are also character arrays which are arrays of characters terminated by a null character ('\0'), so pointer arithmetic becomes an efficient tool to traverse, search, and manipulate the characters directly through their memory locations.
We can do all the pointer arithmetic operations with strings except assignment to NULL.
Let's see how the pointer arithmetic helps in simplifying different operations in C strings.
Strings are not same
As we can see, No index variable needed. Faster, shorter, and cleaner code.
Geeks
Using pointers, we do direct element assignment via pointers.
Geeks
As we can see, working with strings get simpler and concise by using pointers and pointers arithmetic. This behaviour is not outside the normal behaviour of the strings as the strings in the end are just block of memory.