when we define a string like

char *name = some_name;

and then print it

printf("your name is %s",name);

how does know where to stop while printing as we didn't include a '/0' at the end?

1 Answer 1


Character pointers are normally used to build literal strings, the most usual way is to make a statement of the following type:

char *name = "my name is very long";

Some things you need to know about this statement.

It is enclosed in double quotes.

The pointer name points to the first elements of the string.

It is read-only or constant, if we try to change the value of name doing, for example name [0] = 'w', it will cause a segfault.

The string ends automatically in the character '\0'.

It is convenient to read something about the difference between a variable of type char * and an array of characters of type

char name [3] = {'a', 'b', 'c'};

But if you have doubts and do not see it clearly I suggest a new question, suggestion: it is always a good idea to learn by yourself, only when it is impossible to move forward you can ask.

  • Thank you!! @MARS
    – Rohit Jain
    Jul 12, 2019 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .