strcmp( ) function is basically used in c program for comparing two string assertion(arguments) together.
![]() |
| strcmp( ) in C |
Through this article we will try to cover whole basis queries about strcmp( ) in detail so if you have any doubt related to this topic then you will be go with this article....
Topics:-
- strcmp( ) function in c
- strcmp( ) function in c example
- strcmp( ) function in c syntax
- header file for strcmp( ) function in c
- what does strcmp( ) return ?
strcmp( ) function in C
strcmp( ) function is also known as a built in function or standard library function of C but it is widely know as string function. strcmp( ) function is basically used to compare two string assertion(argument) character by character. strcmp( ) function compare two string together on the basis of ASCII value of each character, which are already define in C compiler.
Return value of strcmp( ) function in C
strcmp( ) function may be return three possible integer value based on the comparison...
- Zero( 0 ) : This value is return when ASCII value of both strings are equal.
- Greater than Zero( >o) : When the ASCII value of first string is greater than second string.
- Less than Zero( <0) : When the ASCII value of second string is greater than first string.
Header file of strcmp( ) function in C
strcat( ) function is a built in function of C and it is define in <string.h> header file.
syntax of strcmp( ) function in C
strcmp( str1,str2);
Example of strcmp( ) function in C
#include<stdio.h>
#include<string.h>
int main()
{
int n;
char str[15]="Akash";
char str1[15]="Ashish";
n=strcmp(str,str1);
if(n>0)
{
printf("str is greater than str1");
}
else if(n<0)
{
printf("str is less than str1");
}
else
{
printf("both string are equal");
}
return 0;
}
____________________________________
____________________________________Conclusion
strcmp( ) function is basically used in c program for comparing two string character by character on the basis of ASCII value.

