The same notation is used for pointing at a single character or the first character of a null-terminated string:

char c = 'Z';
char a[] = "Hello world";

char *ptr1 = &c;
char *ptr2 = a;      // Points to the 'H' of "Hello world"
char *ptr3 = &a[0];  // Also points to the 'H' of "Hello world"
char *ptr4 = &a[6];  // Points to the 'w' of "world"
char *ptr5 = a + 6;  // Also points to the 'w' of "world"

The values in ptr2 and ptr3 are the same; so are the values in ptr4 and ptr5. If you're going to treat some data as a string, it is important to make sure it is null terminated, and that you know how much space there is for you to use. Many problems are caused by not understanding what space is available and not knowing whether the string was properly null terminated.

Note that all the pointers above can be dereferenced as if they were an array:

 *ptr1    == 'Z'
  ptr1[0] == 'Z'

 *ptr2    == 'H'
  ptr2[0] == 'H'
  ptr2[4] == 'o'

 *ptr4    == 'w'
  ptr4[0] == 'w'
  ptr4[4] == 'd'

  ptr5[0] ==   ptr3[6]
*(ptr5+0) == *(ptr3+6)

Late addition to question

What does char (*ptr)[N]; represent?

This is a more complex beastie altogether. It is a pointer to an array of N characters. The type is quite different; the way it is used is quite different; the size of the object pointed to is quite different.

char (*ptr)[12] = &a;

(*ptr)[0] == 'H'
(*ptr)[6] == 'w'

*(*ptr + 6) == 'w'

Note that ptr + 1 points to undefined territory, but points 'one array of 12 bytes' beyond the start of a. Given a slightly different scenario:

char b[3][12] = { "Hello world", "Farewell", "Au revoir" };

char (*pb)[12] = &b[0];

Now:

(*(pb+0))[0] == 'H'
(*(pb+1))[0] == 'F'
(*(pb+2))[5] == 'v'

You probably won't come across pointers to arrays except by accident for quite some time; I've used them a few times in the last 25 years, but so few that I can count the occasions on the fingers of one hand (and several of those have been answering questions on Stack Overflow). Beyond knowing that they exist, that they are the result of taking the address of an array, and that you probably didn't want it, you don't really need to know more about pointers to arrays.

Answer from Jonathan Leffler on Stack Overflow
Top answer
1 of 3
35

The same notation is used for pointing at a single character or the first character of a null-terminated string:

char c = 'Z';
char a[] = "Hello world";

char *ptr1 = &c;
char *ptr2 = a;      // Points to the 'H' of "Hello world"
char *ptr3 = &a[0];  // Also points to the 'H' of "Hello world"
char *ptr4 = &a[6];  // Points to the 'w' of "world"
char *ptr5 = a + 6;  // Also points to the 'w' of "world"

The values in ptr2 and ptr3 are the same; so are the values in ptr4 and ptr5. If you're going to treat some data as a string, it is important to make sure it is null terminated, and that you know how much space there is for you to use. Many problems are caused by not understanding what space is available and not knowing whether the string was properly null terminated.

Note that all the pointers above can be dereferenced as if they were an array:

 *ptr1    == 'Z'
  ptr1[0] == 'Z'

 *ptr2    == 'H'
  ptr2[0] == 'H'
  ptr2[4] == 'o'

 *ptr4    == 'w'
  ptr4[0] == 'w'
  ptr4[4] == 'd'

  ptr5[0] ==   ptr3[6]
*(ptr5+0) == *(ptr3+6)

Late addition to question

What does char (*ptr)[N]; represent?

This is a more complex beastie altogether. It is a pointer to an array of N characters. The type is quite different; the way it is used is quite different; the size of the object pointed to is quite different.

char (*ptr)[12] = &a;

(*ptr)[0] == 'H'
(*ptr)[6] == 'w'

*(*ptr + 6) == 'w'

Note that ptr + 1 points to undefined territory, but points 'one array of 12 bytes' beyond the start of a. Given a slightly different scenario:

char b[3][12] = { "Hello world", "Farewell", "Au revoir" };

char (*pb)[12] = &b[0];

Now:

(*(pb+0))[0] == 'H'
(*(pb+1))[0] == 'F'
(*(pb+2))[5] == 'v'

You probably won't come across pointers to arrays except by accident for quite some time; I've used them a few times in the last 25 years, but so few that I can count the occasions on the fingers of one hand (and several of those have been answering questions on Stack Overflow). Beyond knowing that they exist, that they are the result of taking the address of an array, and that you probably didn't want it, you don't really need to know more about pointers to arrays.

2 of 3
11

The very same. A C string is nothing but an array of characters, so a pointer to a string is a pointer to an array of characters. And a pointer to an array is the very same as a pointer to its first element.

🌐
Scaler
scaler.com › home › topics › string pointer in c
String Pointer in C - Scaler Topics
January 16, 2024 - In this case, ptr points to the starting character in the array arr i.e. H. To get the value of the first character, we can use the * symbol, so the value of *ptr will be H. Similarly, to get the value of ith character, we can add i to the pointer ptr and dereference its value to get ith character, as shown below. Instead of incrementing the pointer manually to get the value of the string, we can use a simple fact that our string terminates with a null \0 character and use a while loop to increment the pointer value and print each character till our pointer points to a null character.
Discussions

HELP ME WITH POINTERS AND STRINGS!
In your example, "hello" is an array of six characters having the values 'h', 'e', 'l', 'l', 'o', '\0'. It's allocated in an unspecified location and while the compiler lets you cheat and lose the constness, you shouldn't attempt to change this. You then try to initialize S with it. S is a pointer to a (single) char. C gives you a free conversion from array of x to pointer to the x and uses the address of the first element. IN this case s is pointing at the h. Your while loop checks where s points (*s) to see if it is not equal to '\0' (I assume you really wanted char and while not Char and While and \0 not /0). If it is not equal, then the body of the while runs which increments S. The loop ends with S is pointing at the \0. More on reddit.com
🌐 r/C_Programming
12
0
June 21, 2024
String literal as pointers?
In C, there is not actual 'string' type, as there is in many other languages. Instead, a string is simply an array of characters. The string literal syntax ("A begining with the characters written literally inside, terminated with another quote character") is syntactic sugar for this. The type for all array's in C is the same: a pointer (memory address) to the element type. For example, an array of integers is int *. For strings, because it is an array of characters, the type of a string value or variable is char * More on reddit.com
🌐 r/C_Programming
9
0
February 3, 2020
How to return a pointer to a string in C - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 7 years ago. I tried to develop a function which take a string reverse letters and return pointer to string. More on stackoverflow.com
🌐 stackoverflow.com
Assigning strings to pointer in C - Software Engineering Stack Exchange
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... My question is about pointers in C. As far as I've learned and searched, pointers can only store addresses of other variables, but cannot store the actual values (like integers or characters). But in the code below the char pointer c actually storing a string... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
July 11, 2014
People also ask

Can I use a string pointer in a struct?
Yes. It's common in C to use char* in structures to hold names, messages, or any string data. Just ensure you allocate or assign memory correctly before using it.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › string pointer in c
String Pointer in C: Complete Beginner Guide
Can I return a string pointer from a function?
Yes, but you should be careful. You can return a pointer to a string allocated with malloc or a global/static variable. Never return a pointer to a local array—it becomes invalid after the function exits.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › string pointer in c
String Pointer in C: Complete Beginner Guide
Are string pointers faster than arrays for string manipulation?
Yes, in many cases. Since pointers allow direct memory access and pointer arithmetic, they can be more efficient than array indexing, especially in loops and low-level operations.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › string pointer in c
String Pointer in C: Complete Beginner Guide
🌐
Microchip Developer Help
developerhelp.microchip.com › xwiki › bin › view › software-tools › compilers › c-programming › data-pointers › pointers-strings
C Programming Pointers and Strings - Developer Help
August 26, 2025 - The string itself will be stored in memory, and the pointer will be given the address of the first character of the string. ... Please note that implementation varies depending on the compiler and architecture used. When initialized, a pointer to a string points to the first character:
🌐
Reddit
reddit.com › r/c_programming › help me with pointers and strings!
r/C_Programming on Reddit: HELP ME WITH POINTERS AND STRINGS!
June 21, 2024 -

Hi, i don't really understand something about strings and pointers So basically a string is an character array ( correct me if im wrong) and we all know that the name of an array is a constant pointer which means we cannot increment or decrement it Although that i found sometimes they do increment the pointer For exemple

Char*S="hello"; While((*S)!='/0') S++ Please someone explain to me the difference between a string and a character array along with pointers!!

🌐
GeeksforGeeks
geeksforgeeks.org › c language › array-of-pointers-to-strings-in-c
Array of Pointers to Strings in C - GeeksforGeeks
November 14, 2025 - Each array element will act as a pointer to the first character of an individual string.
🌐
DataFlair
data-flair.training › blogs › string-using-pointers-in-c
String using Pointers in C - DataFlair
March 9, 2024 - Pointers in C provide an efficient way to access and modify strings by directly pointing to characters in a string.
Find elsewhere
🌐
DEV Community
dev.to › missmati › pointers-arrays-strings-in-c-52h3
Pointers , Arrays & Strings in C - DEV Community
October 11, 2022 - Similar to the 2D array we can create the string array using the array of pointers to strings. Basically, this array is an array of character pointers where each pointer points to the string’s first character.
🌐
Dyclassroom
dyclassroom.com › c › c-pointers-and-strings
C - Pointers and Strings - C Programming - dyclassroom | Have fun learning :-)
So, we can create a character pointer ptr and store the address of the string str variable in it. This way, ptr will point at the string str. In the following code we are assigning the address of the string str to the pointer ptr.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-create-a-pointer-for-strings-using-c-language
How to create a pointer for strings using C language?
Here, each element array_name[i] is a pointer to the base address of the corresponding string. No fixed memory size requirement − strings occupy only the necessary bytes ... #include <stdio.h> int main() { char *a[5] = {"one", "two", "three", "four", "five"}; int i; printf("The strings are: "); for (i = 0; i < 5; i++) { printf("%s ", a[i]); } printf("<br>"); return 0; }
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › string pointer in c
String Pointer in C: Complete Beginner Guide
May 25, 2026 - This section demonstrates how to use pointers to reference either string literals or character arrays, explaining how memory handling differs.
🌐
Codedamn
codedamn.com › news › c programming
Accessing String Using Pointers in C
March 10, 2024 - They are powerful tools for string manipulation, allowing programmers to modify strings without copying them entirely. To declare a pointer to a string, you can use the syntax char *ptr = "hello";. This statement creates a pointer ptr that points ...
🌐
Log2Base2
log2base2.com › C › pointer › print-string-using-pointer-in-c.html
Print string using pointer in c
Let's change the 4th(index 3) character 'l' as 'o'. The new string will be "Heloo". ... /* * Program : Manipulating string using pointer * Language : C */ #include<stdio.h> int main() { char str[6] = "Hello"; char *ptr; int i; printf("String = %s\n", str); //string name itself a base address of the string ptr = str; //ptr references str //change the 4th char as 'o' *(ptr+3) = 'o'; printf("Updated string = %s\n",str); return 0; } Run it
🌐
Medium
medium.com › @muirujackson › char-pointer-to-string-in-c-aa4b59fdf289
Declaration of String in C. In C, char [] and char * are both used… | by Muiru Jackson | Medium
April 6, 2023 - In summary, char [] and char * are both used to represent strings in C, but they have different memory allocation, size, mutability, initialization, and function parameter passing behavior.
🌐
BeginnersBook
beginnersbook.com › 2019 › 02 › c-program-to-print-string-using-pointer
C Program to Print String using Pointer
We have assigned the array base address (address of the first element of the array) to the pointer and then we have displayed the every element of the char array by incrementing the pointer in the while loop. #include <stdio.h> int main() { char str[100]; char *p; printf("Enter any string: "); fgets(str, 100, stdin); /* Assigning the base address str[0] to pointer * p.
🌐
Scribd
scribd.com › document › 648188660 › Copy-of-C-1
Pointers and Strings in C Programming | PDF | Pointer (Computer Programming) | Variable (Computer Science)
Common string functions in C include scanf(), gets(), puts(), and strlen().Read more ... Pointers in C programming store the address of a variable in memory. Pointers must be declared with a data type that matches the variable being pointed ...
🌐
RIT
se.rit.edu › ~swen-250 › activities › MicroActivities › C › mu_string_ptr_update › distrib › index.html
C Strings with Arrays and Pointers
February 27, 2025 - Arrays can be declared with an explicit size: char buffer[MAXSIZE+1] ; // hold a string of at most MAXSIZE characters + terminating NUL ('\0') Arrays can be initialized, which sets the array's size and the initial contents: char mesg[] = "Hello!" ; // a 7 element array - 6 characters in Hello! + terminating NUL · An array name is a constant pointer to the first (0th) array element; thus: mesg == &mesg[0] ; // address of the first character in the message.
Top answer
1 of 2
2

There are multiple mistakes in the shared code, primarily -

  • s++; move the pointer till '\0'. It should be brought back 1 unit to point to actual string by putting s--. Other wise the copied one will start with '\0' that will make it empty string.
  • Magic numbers 20 and 13. where in malloc() 1 + length of s should be sufficient instead or 20. For 13 just move a unit ahead and put '\0'

However, using string.h library functions() this can be super easy. But I think you are doing it for learning purpose.

Therefore, Corrected code without using string.h lib function() should look like this:

char *reverseStr(char s[])
{
    printf("Initial string is: %s\n", s);

    int cCounter = 0;
    while(*s != '\0')
    {
        cCounter++;
        s++;
    }
    s--; //move pointer back to point actual string's last charecter

    printf("String contains %d symbols\n", cCounter);

    char *result = (char *) malloc(sizeof(char) * ( cCounter + 1 ));
    if( result == NULL ) /*Check for failure. */
    {
        puts( "Can't allocate memory!" );
        exit( 0 );
    }

    char *tempResult = result;
    for (int begin = 0; begin < cCounter; begin++)
    {
        *tempResult = *s;
        s--; tempResult++;
    }
    *tempResult =  '\0';
    //result[cCounter+1] = '\0';
    return result;
}

Calling from main

int main()
{
    char testStr[] = "Hello world!";
    char *pTestStr;

    puts("----------------------------------");
    puts("Input a string:");
    pTestStr = reverseStr(testStr);
    printf("%s\n", pTestStr);
    free(pTestStr);
}

Output

----------------------------------
Input a string:
Initial string is: Hello world!
String contains 12 symbols
!dlrow olleH

As per WhozCraig suggestion just by using pointer arithmetic only -

char *reverseStr(const char s[])
{
    const char *end = s;
    while (*end)
        ++end;

    char *result = malloc((end - s) + 1), *beg = result;
    if (result == NULL)
    {
        perror("Failed to allocate string buffer");
        exit(EXIT_FAILURE);
    }

    while (end != s)
        *beg++ = *--end;
    *beg = 0;

    return result;
}
2 of 2
0

Your code can be simplified using a string library function found in string.h

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

char *reverseStr(char s[])
{
    printf("Initial string is: %s\n", s);
    int cCounter = strlen(s);
    char *result = malloc(cCounter + 1);

    printf("String contains %d symbols\n", cCounter);

    int begin = cCounter;

    for(; cCounter > 0; cCounter--)
    {
        result[begin - cCounter] = s[cCounter - 1];
    }
    result[begin] = '\0';   
    return result;
}

int main()
{
    char testStr[] = "Hello world!";
    char *pTestStr;

    puts("----------------------------------");
    puts("Input a string:");
    pTestStr = reverseStr(testStr);
    printf("%s\n", pTestStr);
    free(pTestStr);
    return 0;
}

Output:

----------------------------------
Input a string:
Initial string is: Hello world!
String contains 12 symbols
!dlrow olleH
Top answer
1 of 2
13

This is just the way string literals work in C. String literals like "name" are arrays of characters, it is equivalent to the five element array {'n', 'a', 'm', 'e', '\0'}. For the code

char *c;
c="name";

the environment reserves memory for the above array already at initialization time, when the program is loaded from disk into memory. At run time, the adress of the beginning of that array is assigned to c.

Note the first piece of code of yours is not equivalent to the second, because in the first piece you assign a string literal (and not a character like 'n') to a char* variable. In the second, you try to assign an int (and not an int array) to an int*.

Here is a tutorial on strings and pointers in C with a more detailed explanation.

2 of 2
3

String literals like "name" are stored as arrays of char (const char in C++) such that they are allocated when the program starts and held until the program terminates.

The type of the expression "name" is "5-element array of char" (5th element for the 0 terminator). Except when it is the operand of the sizeof or unary * operators, or is a string literal being used to initialize an array in a declaration, an expression of type "N-element array of T" will be converted ("decay") to an expression of type "pointer to T", and the value of the expression will be the address of the first element of the array.

So, when you write

c="name";

"name" is not the operand of the sizeof or unary * operators, and it isn't being used to initialize an array in a declaration, so the address of the first element of the string is being assigned to the pointer variable c. Essentially, what you have in memory is something like the following:

            +-----+
"name"[0] : | 'n' |  <-------+
            +-----+          |
"name"[1] : | 'a' |          |
            +-----+          |
"name"[2] : | 'm' |          |
            +-----+          |
"name"[3] : | 'e' |          |
            +-----+          |
"name"[4] : |  0  |          |
            +-----+          |
              ...            |
            +-----+          |
        c : |     | ---------+
            +-----+