char *str; str=“HELLO”; How does that work without allocating any memory for the string?
问题 Code: #include <stdio.h> int main() { char *str; char i = 'a'; str = &i; str = "Hello"; printf("%s, %c, %x, %x", str, i, str, &i); return 0; } I get this output: Hello, a, 403064, 28ff0b I have following two doubts: How can I store a string without allocating any memory for it. str is a character pointer and is pointing to where char variable i . When I add str = "Hello"; aren't I using 5 bytes from that location 4 of which are not allocated? Since, I code str = &i; shouldn't str and &i have