How are Strings represented in memory in C?
a) As an array of characters
b) As a linked list
c) As a single character
d) As a floating-point number
Answer:
a) As an array of characters
Explanation:
In C, strings are represented in memory as an array of characters terminated by a null character ('\0'
). Each character in the string occupies one byte of memory, and the null character marks the end of the string. This null-terminated array allows C functions to determine where the string ends, enabling operations like copying, concatenation, and comparison.
Understanding how strings are represented in memory is essential for handling string manipulation effectively and avoiding errors like buffer overflows.