C-string definition in C / C ++

What does the word "C-string" really mean in C / C ++? Pointer to a char? An array of characters? Or maybe an array of const-pointer / const characters?

+5
source share
4 answers

A String "C" is an array of characters ending in byte 0 (null character). An array, not any pointer, is a string. Thus, any finite subset of a string C is also a string C. Pointers of type char *(or const char *etc.) are often considered pointers to strings, but they actually point to a string element, usually considered as a pointer to the original element of a string.

+7
source

Const , 0 char. , C:

char string_one[] = { 'H', 'e', 'l', 'l', 'o', 0 };
char string_two[] = "Hello"; // trailing 0 is automagically inserted by the compiler
const char *string_three = "Hello";
+7

C- , 0 , . (char[]), (char *).

In C ++, there is another type of string with a name std::stringthat should not end with 0 byte. The term C string is often used by C ++ programmers when they mean a null terminated string, not a type std::string.

+2
source

According to the standard (C11 ยง7.1.1), a string is a continuous sequence of characters ending in and including the first null character, i.e. character array ending in '\0'.

+1
source

All Articles