Correct a plant label
Before you start this advanced track
Arrays and functions, plus the basics of memory addresses, pointers, and byte sizes.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Predict the result.
What plant label is printed?
#include <stdio.h>int main(void) { char label[] = "moss"; label[0] = 'M'; printf("%s\n", label); return 0;}Each example is a complete C11 console program. Compile as C, not C++. Arrays are local objects with the sizes shown; no input or external files are needed.
Review the lesson
A character array initialized from a string contains editable characters followed by a terminating zero byte. Array indexes begin at zero. Assigning a single-quoted character to one array element replaces just that character. The %s format prints the characters through the end of the string, stopping before its zero terminator.