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?

19th Oct 2016, 9:05 AM
Mayank
Mayank - avatar
2 Answers
+ 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.
19th Oct 2016, 10:59 AM
Zen
Zen - avatar
0
Not only necessary but also, you have to give same data type as your variable.
24th Oct 2016, 12:29 AM
S M Sarwar
S M Sarwar - avatar