Hello. ^^
I would like to know why most pointers of most languages restricted to pointing at a single type object. Is it because for readability purposes? Memory address? Or another reason?
Thanks. :)
Hello. ^^
I would like to know why most pointers of most languages restricted to pointing at a single type object. Is it because for readability purposes? Memory address? Or another reason?
Thanks. :)
It's a pragmatic issue, really: You can't do much with a pointer unless you know something about the structure of what it points to. And if you get it wrong, you typically corrupt your data and you can very easily crash the program.
PASCAL allows you to overlay pointers using the "union" construct -- having one pointer point to several different kinds of things.
C/C++ support "void pointers" with the "void *" syntax. This means "this is a pointer to something, but I'm not telling you anything about what it points to." C/C++ gives you a lots of freedom to arbitrarily change one pointer type to another, to move pointers around, to reinterpret them, and to corrupt memory and crash the program. ;->
Java is unusually strict in its handling of pointers. You can't corrupt memory or crash the program in Java. (...except in the sense that throwing exceptions can terminate a program -- in a controlled and well defined manner.)
Sorry for the late response. ^^;;
Anyway, thanks for the reply.
C/C++'s pointers are strong but I guess, we really need to be extra careful when using them.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.