C-style strings and the string.h functions, multidimensional arrays, structs, unions, enums, typedef and bit fields.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a C-style string?
Show answer
A null-terminated character array, where the last character is the null terminator '\0'.
- What does strlen() do?
Show answer
Returns the number of characters in a string, not including the null terminator.
- What does strcpy() do?
Show answer
Copies one string to another, including the null terminator.
- Why is strcpy() considered dangerous?
Show answer
It does not check buffer size and can cause buffer overflow if the source is too large.
- What is the safer alternative to strcpy()?
Show answer
strncpy(), which takes a maximum number of characters to copy.
- What does strcat() do?
Show answer
Concatenates (appends) one string to the end of another.
- What does strcmp() return?
Show answer
Returns 0 if strings are equal, negative if first is less, positive if greater.
- What does strchr() find?
Show answer
Locates the first occurrence of a character in a string and returns a pointer to it.
- What does strstr() find?
Show answer
Locates the first occurrence of a substring within a string and returns a pointer to it.
- What does strtok() do?
Show answer
Splits a string into tokens (substrings) based on delimiter characters.
- What header file contains string functions?
Show answer
string.h (or cstring in C++)
- How do you declare a character array to hold a 50-character string?
Show answer
char str[51]; (the +1 accounts for the null terminator)
- What is the difference between a string literal and a character array?
Show answer
A string literal is constant and read-only; a character array is mutable storage that can be modified.
- How do you initialize a string with a value?
Show answer
char str[] = "hello"; or char str[6] = "hello";
- What is a multidimensional array?
Show answer
An array of arrays, such as a 2D array that represents rows and columns.