I want to know why this program is executing output like this " -111 111 0" briefly .

Status
Not open for further replies.

praveenkumar450

Newbie level 5
Joined
Jul 2, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Hyderabad, Andhra Pradesh, India
Activity points
55
I want to know why this program is executing output like this " -111 111 0" briefly .

Code:
#include <stdio.h>
#include <string.h>
int main() {
  char string1[20];
  char string2[20];

  strcpy(string1, "Hello");
  strcpy(string2, "Hellooo");
  printf("Return Value is : %d\n", strcmp( string1, string2));

  strcpy(string1, "Hellooooo");
  strcpy(string2, "Hello");
  printf("Return Value is : %d\n", strcmp( string1, string2));

  strcpy(string1, "Hellooo");
  strcpy(string2, "Hellooo");
  printf("Return Value is : %d\n", strcmp( string1, string2));

  return 0;
}
 

Re: I want to know why this program is executing output like this " -111 111 0" brief

strcmp() returned values are as follows:
if Return value if < 0 then it indicates str1 is less than str2

if Return value if > 0 then it indicates str2 is less than str1

if Return value if = 0 then it indicates str1 is equal to str2
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…