0
is it necessary to give pointers data type while declaring?
i read that pointers have data type to what it is pointing too so is it necessary to give them data type while declaring, shouldn't it automatically takes data type of where it is pointed too?
2 Respostas
+ 6
What you give to a pointer is an address, and you can't deduce from an address the type of data stored there.
The whole point of a data type is to indicate how the data has to be interpreted as.
You can declare a generic (void*) pointer and assign it an address, but even then, you still have to indicate the data type when dereferencing.
0
Not only necessary but also, you have to give same data type as your variable.