NULL TERMINATOR ∙ '\0' is the null terminator. ∙ It is an unprintable character. ∙ It goes right after the last character in a string, in memory. ∙ Do not print the null terminator. ∙ Null terminator only exists in memory, not in files. ∙ Any string literal (e.g., "ABC") implies the null terminator. ∘ s2 and s3 are both arrays of 4 characters (not 3). ∙ Null terminator tells C functions that work with strings when they have reached the end. ∘ Without it they will go on reading into other memory that they shouldn't touch. ∙ If you accidentally print '\0' to the terminal, you won't see anything. ∘ If you redirect the output to a file and open in Vim, you will ^@ for the null terminator. '\n' is an escape code for the newline character (ASCII value 10 or 0x0a). Escape codes take 2 characters in your C code, but result in 1 character in memory. '\n' is 1 character in memory. Same is true for '\"' or '\0' or '\\'. ____________________________________________________________ HOW TO CHECK IF YOUR CODE IS ACCIDENTALLY PRINTING THE NULL TERMINATOR ('\0') $ vim c.actual.txt # You will see ^@ for the null terminator if present. $ gcc c.c -o c $ ./c > c.actual.txt $ xxd -g1 c.actual.txt 0000000: 41 42 43 00 0a ABC.. ▲ ┌─────┘ # The 00 above indicates that the null terminator ('\0') was in the c.actual.txt file, # and thus was printed by the program. (0a is the '\n'.) $ ./c | xxd -g1 0000000: 41 42 43 00 0a ABC.. ▲ ┌─────┘ # The 00 above indicates that the null terminator ('\0') was printed when we ran ./c. ____________________________________________________________ VARIADIC FUNCTIONS 1. Create a variable of type va_list. Name should be like more_args (or similar). va_list more_args; 2. Call va_start(…) to initialize more_args. va_start(more_args, ███); // where ███ is the name of the parameter just before ... in the // function signature 3. Use va_arg(…) to access ONE additional argument. … = va_arg(more_args, ███); // where ███ is the type of the argument you expect to find. // For example, if you expect to find an int, you might have // int next_int_arg = va_arg(more_args, int); 4. Call va_end(…) to finalize. va_end(more_args); ⚠ You can only access the additional arguments in order. ⚠ Variadic arguments are not stored in an array. ⚠ Do not call va_arg(…) too many times.