0

Was expecting it print out "different" since I've created 2 different variables and stored the same values MANUALLY TYPED OUT. According to lecture 4, strings are pointers and when compared, they should compare the address of the first element of the array. But turns out, they're the same addresses.. How?

#include <stdio.h>

int main(void)
{
    char *s = "TEST";
    char *t = "TEST";

    if (s == t)
    {
        printf(" same \n %p \n %p \n",s,t);
    }
    else
    {
        printf(" different \n %p \n %p \n",s,t);
    }
}
1

You must log in to answer this question.

Browse other questions tagged .