Overview :

The "strcmp" is used for comparing two strings.

Syntax :
int strcmp(const char * s1,const char *s2);
Description :

The "strcmp" function accepts 2 arguments

  • char *s1 -> string to be compared - the first string

  • char *s2 -> string to be compared - the second string

  • The strcmp functions compares the two given strings and returns an integer value.

The 'strcmp' function returns

0 - if the two strings are equal
integer less than 0 - if s1 is less than s2
integer greater than 0 - if s1 is greater than s2

Example :
using namespace std;

int main()
  char str1[10];

  cout<<"enter string 1";

  if(strcmp(str1,"cheraus") == 0) 
     cout<<"strings are equal";
    cout<<"string not equal";

 return 0;


comments powered by Disqus