I am so curious why for strncpy_s, when I set the second parameter numberOfElements to 1, it does not copy the first character to the destination. And when I set it to 2, it copy the first one to destination.
strncpy_s(a, 1, "1+1=2", _TRUNCATE);
Then in debugger, I found a = 0'\0'. Why it is not a = '1'?
Because the string "1" takes up two bytes and there's only room for one.
A C-style string has to have a terminating zero byte, otherwise there is no way to know its length. With just space for one character, the only possible legal string is just a terminator.