Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
示例:strncmp("John", "Johny") 似乎这个示例在没有第三个参数的情况下仍然有效。
谁能解释一下?我在 C 文档中找不到任何解释。
谢谢。
您忘记包含相关的头文件:
#include <string.h>
请启用所有编译器警告并修复它们。
我猜undefined behaviour。在 C 系统期望找到n参数的地方,它偶然发现了一个大于两个测试字符串长度的数字。
undefined behaviour
n
换句话说,您幸运的部分原因是忽略了警告。