Discussion: String or Not?
Execute the code to understand the output and gain insights into null terminators.
We'll cover the following...
Run the code
Now, it's time to execute the code and observe the output.
#include <stdio.h> int main() { char nonstring[] = { 'g', 'r', 'e', 'e', 't', 'i', 'n', 'g', 's', ',', ' ', 'h', 'u', 'm', 'a', 'n' }; char data[] = { 127, 129, 255 }; printf("%s\n", nonstring); return(0); }
C code for the given puzzle
Understanding the output
If you’re lucky, the output appears like this:
greetings, human0?u??
Code output
Note: Garbage values can vary from one compiler to another.
If you’re unlucky, you see far more garbage spew all over the terminal window. In some rare cases you may see nothing, depending on the code page or font used for the terminal ...