Does an empty string "" have an address ?

In this hazy afternoon, our team is in hot Sprint2 design discussion.  Abruptly, I've got a doubt if empty string holds an address or not. Hence this post was generated.

Yes. I concluded that empty string holds an address always. Only pointer which returns NULL will not hold an address. NULL pointer points at nothing.

#include<stdio.h>
char *function(char *obj, int dbstate)
{
    char *value = "";
    if (!obj) {
        printf("obj is NULL\n");
        return "";
    }
    if (dbstate) {
        value = "shirley";
    }
    return value;
}
main()
{
    char *obj = "rose";
    char *ret = NULL;
    ret = function(obj, 0);
    if (!ret) {
        printf("ret address is NULL");
    } else {
        printf("ret address %x\n",ret);
        printf("ret address %sEnd\n",ret);

    }
}

Output :

admin@Shirley:~/Documents$ ./em
ret address 4006c4
ret address End


Comments