Inconsistent strcmp() return value when passing strings as pointers or as literals
I was playing around with strcmp when I noticed this, here is the code: #include <string.h> #include <stdio.h> int main(){ //passing strings directly printf("%d\n", strcmp("ahmad", "fatema")); //passing strings as pointers char *a= "ahmad"; char *b= "fatema"; printf("%d\n",strcmp(a,b)); return 0; } the output is: -1 -5 shouldn't strcmp work the same? Why is it that I am given different value when I pass strings as "ahmad" or as char* a = "ahmad" . When you pass values to a function they are allocated in its stack right? Shafik Yaghmour You are most likely seeing the result of a compiler