+ 2

Pointers Confusion

Key confusions What i understood from chatbot(requires a bit hardware knowledge which i don't have) 1.char* ptr = "String" means ptr points to a read-only string. often in the .rodata section of the program. 2.Reassigning ptr just changes the pointer, not the original string. ptr now points to a new string .The old string still exists in memory, but ptr no longer points to it. 3.String literals are statically allocated by the compiler. They exist before your program runs (loaded into memory when the executable starts). But 1 question remains : Isn't character array, an array therefore a pointer itself?How could there be 2 variants in declaration then? https://sololearn.com/compiler-playground/cz70783YtI4t/?ref=app

25th Jul 2025, 5:18 PM
Nahid Alom Neshad (Nahid)
Nahid Alom Neshad (Nahid) - avatar
3 Réponses