VOOZH about

URL: https://www.geeksforgeeks.org/c/pointer-arithmetic-with-strings/

⇱ Pointer Arithmetic with Strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Pointer Arithmetic with Strings

Last Updated : 11 Jun, 2025

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.

  • Increment/Decrement a Pointer.
  • Addition/Subtraction of Integer to/from a Pointer.
  • Comparison of Pointers in a String.
  • Pointer Traversal in Strings.

Let's see how the pointer arithmetic helps in simplifying different operations in C strings.

1. String Comparision


Output
Strings are not same

As we can see, No index variable needed. Faster, shorter, and cleaner code.

2. String Copying


Output
Geeks

Using pointers, we do direct element assignment via pointers.

3. String Length Calculation

4. String Concatenation


Output
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.

Comment
Article Tags: