C Programming

⌘K
  1. Home
  2. Docs
  3. C Programming
  4. Pointers
  5. Pointers and Character Strings

Pointers and Character Strings

Strings in C are arrays of characters terminated by a null character ‘\0’.

  • You can use pointers to access and manipulate strings.
  • Pointer arithmetic helps traverse strings character by character.
  • A string literal can be assigned to a char * pointer.
  • Dereferencing and pointer arithmetic allow access to each character.

Example:

#include <stdio.h>

int main() {
    char str[] = "Hello";
    char *ptr = str;

    while (*ptr != '\0') {
        printf("%c ", *ptr);
        ptr++;
    }
    printf("\n");

    return 0;
}

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *