Quick strlen question

Posted by LearningC on Stack Overflow See other posts from Stack Overflow or by LearningC
Published on 2010-04-23T20:45:26Z Indexed on 2010/04/23 20:53 UTC
Read the original article Hit count: 268

Filed under:

Hi again. I've come to bother you all with another probably really simple C question.

Using the following code:

int get_len(char *string){

    printf("len: %lu\n", strlen(string));

    return 0;
}

int main(){

    char *x = "test";
    char y[4] = {'t','e','s','t'};

    get_len(x); // len: 4
    get_len(y); // len: 6

    return 0;
}

2 questions. Why are they different and why is y 6? Thanks guys.

© Stack Overflow or respective owner

Related posts about c