Silgy

The ultimate answer to a sizeof and char arrays question:

char test1[100]; char *test2 = (char*)malloc(100);

Silgy server is trying the above code live and says this:

sizeof(test1) = 100 sizeof(test2) = 8 STRCPY test2 [abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789]

Additionally – let's try test1's size when passed as an argument:

void sizeoftest(char *test_arg) { sizeof(test_arg) = 8 } sizeoftest(test1);

STRCPY test1 [abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789]

void sizeoftest(char *test_arg) { sizeof(test_arg) = 8 } sizeoftest(test1);

STRCPY test11 [abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789]

Don't forget:

free(test2);


Copyright © 2018–2020 Jurek Muszyński