Can I assign the address of a integer variable to the float pointer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can I assign the address of a integer variable to the float pointer?

for example int a=4; float *aPtr; aPtr = &a;

14th Feb 2017, 5:02 PM
memol
3 Answers
+ 4
Declaring a pointer to be a specific type tells the compiler when the pointer is dereferenced the value pointed to will be of that type. if you run a code like that one, it would give an error: "cannot convert 'int* ' to 'float*' in inicialization", You can only assign addresses to pointers of the same type.
17th Feb 2017, 2:52 AM
Anne Livia
Anne Livia - avatar
+ 3
no
14th Feb 2017, 5:36 PM
Anne Livia
Anne Livia - avatar
17th Feb 2017, 1:30 AM
Anne Livia
Anne Livia - avatar