It's the same thing as the strcpy() function:
See? str's contents are not defined when you pass str to strcpy(). That's because strcpy() fills the array! If the function is meant to accept a string and then manipulate the data in some way then you'd need to fill str with something meaningful before you used it. For example:Code:#include <string.h> int main(void) { char str[50]; strcpy(str, "Hello, world!"); return 0; }
puts() isn't designed to accept an undefined string so you'll just get garbage output. So there's no universal "You don't have to fill the character array before passing it to a function" rule. It depends on what the function expects.Code:#include <stdio.h> int main(void) { char str[50]; puts(str); return 0; }