Member-only story

C Style Strings Practice Questions

Marika Lam
2 min readMay 15, 2022

--

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?

--

--

No responses yet