educative.io

While declaring pointer `var var_name *<data_type>`, why data type is needed?

Pointer is supposed to store the memory address, so the pointer declaration could be generic right?
Why do we need to put the data type?
For example:
var intP *int
Here why int is required?

is there a difference between the memory address of string or int?


Type your question above this line.

Course: https://www.educative.io/collection/10370001/6289391964127232
Lesson: https://www.educative.io/collection/page/10370001/6289391964127232/5087608474435584

Hi @Kishore_S

Different data types have different sizes. There is no difference between the memory address itself, but the data type of the pointer indicates how big of a memory chunk needs to be read.

Hope this helped!

1 Like

Thanks, @Hafsa_Kamran. This definitely helped!

1 Like