Member-only story
C Style Strings Practice Questions
1. What is a C-style character string?
The C-style character string originated within the C language and continues to be supported within C++. This string is actually a one-dimensional array of characters which is terminated by a null character ‘\0’.
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
You can also write the above statement as follows.
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

2. What is a null terminator?
When printing a C-style string, std::cout prints characters until it encounters the null terminator.
3. How do you declare a c-style string?
char string[50];
This would declare a string with a length of 50 characters. Do not forget that arrays begin at zero, not 1 for the index number. In addition, a string ends with a null character, literally a ‘\0’ character.
4. How do you declare a static string?
Static String
5. What character ends all strings?
'\0'
6. What function is used to compare 2 strings?
strcmp()
7. What method is used to add one string to the end of another string?
strcat()
8. What are the 2 ways to keep track of the number of items in an array?
The first is to keep a count of how many items are in the array. The second is to use a marker after the last valid item in the array.
To learn more about datastructures and algorithms:
Coursera — Algorithms Specialization (Stanford )
Coursera — Datastructures and Algorithms (HSE)
Coursera — Java Programming and Software Engineering Fundamentals (Duke University)
Coursera — Data Structures and Algorithms Specialization (UCSD)