From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding strings in C

Understanding strings in C - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Understanding strings in C

- [Instructor] A string isn't a data type in the C language. Instead, a character array represents a string. The final character in the array must be the null character. It marks the end of the string and it's not displayed. The null character is ASCII code zero. It's represented as the character literal backslash zero. This character isn't counted in the strings length, but storage must be allocated for the null character which can trip you up if you're not careful. Also, keep in mind that the null character isn't the same as the NULL, all caps, pointer constant. The null character has nothing to do with pointers. To declare a string in C, you create a character array. This array is named string. The square brackets are empty and the string literal is a sign. The compiler allocates the proper amount of storage for the string and the null character is automatically appended to the string literal. Another way to allocate the same string is to specify individual character values, though…

Contents