KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've always wondered how I could get away with this: int main(int argc, char **argv) { printf("%p %s %d\n", &argv[1], argv[1], strlen(argv[1])); char copy[strlen(argv[1]) + 1]; strcpy(copy, argv[1]); printf("%p %s %d\n", ©, copy, strlen(copy)); return 0; } The char array copy gets allocated anyway and the program runs fine, printing out the original and the copy. And Valgrind doesn’t complain about anything. I thought dynamic arrays weren’t possible in C without malloc. Was I wrong?
Tags (comma-separated)
Save Edits
Cancel