What is the Difference between strncmp() and strcmp() ?
strncmp() and strcmp()
1033
21-Jun-2018
Updated on 22-Jun-2018
Prakash nidhi Verma
22-Jun-2018strcmp and strncmp :
null-character of string comes in strcmp for compares both the strings wheres strncmp compares at most num characters of both strings. But if num is equal to the length of either string than strncmp behaves similar to strcmp. if both of the strings passed in the argument with strcmp function is not terminated its create a problem by null char ,then comparison of characters continues till the system crashes. But with strncmp function we can limit the comparison with num paramet.
strncmp(): in C++ This function takes two strings and a number num as arguments and compare at most first num bytes of both the strings.
strcmp(): it's <string.h> header file which is a built-in library function and declared in This function takes compare these two strings lexicographically and it's two strings as arguments.This process will be continued until a characters are unequal.
Syntax: