I want to know why strcmp()
returns different values if used more than once in the same function. Below is the program. The first case I am aware of why it prints -6. But in the second case, why does it print -1?
#include<stdio.h>
#include<string.h>
int main()
{
char a[10] = "aa";
char b[10] = "ag";
printf("%d\n",strcmp(a, b));
printf("%d\n",strcmp("aa","ag"));
return 0;
}
And the output it produces is below
[sxxxx@bhlingxxx test]$ gcc -Wall t51.c
[sxxxx@bhlingxxx test]$ ./a.out
-6
-1
Why is the output of second strcmp()
-1? Is it the Compiler who plays here? If so What is the exact optimization it does?