C TutorialLesson 19Free preview
C Strings
This lesson is part of C · All levels
Summary
Strings in C are actually a set of characters stored in a char array, terminated implicitly by the character null worth '\0'. Since C does not have a dedicated operator for the string, operations such as copying or merging are performed through library functions such as strcpy, strlen, and strcat from the string.h header. String length is obtained by strlen, whereas the size of the array can be known by sizeof. Understanding the terminator is important so that string manipulation is not wrong.
Key points
- String C is a char array enclosed by the character '\0'
- Common functions: strlen (length), strcpy (copy), strcat (joint), strcmp (binding)
- Sizeof returns array sizes including null, strlen counts characters without null
- Always make sure the array capacity is sufficient before copying the string so it doesn't overflow
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.