I just read that we need to give the type of pointers while declaring them in C (or C++) i.e.:
int *point ;
As far as I know, pointers sto
We actually don't need (see below) to declare the type, but we should. The pointer stores information about the objects location, while the type defines how much space it takes in memory.
The size of the object stored at the pointed memory is needed in various cases - array creation, assigment, copying the memory, and finally - creating the object using new
.
However you can still define a void
pointer, if you want to hide (for any reason) the type:
void* dontKnowWhatTypeIsHere;
A void pointer is considered an universal one. It can point to any object, and when we want to use it with a type, we'll just do reinterpret_cast
.