Last mcq question

plz explain question 8 . why is the answer no ?

hello @pratik.win

Ans is No. it wont compile…
compile error is : error: invalid conversion from ‘void*’ to ‘int*’

why?
due to line j = k = &a.
in cpp, void* is a generic pointer and it can point to any type of element.
statements like k=&a, k=j or k=j=&a are all valid…
but j = k is not valid. if you assigns a generic type(void*) to a specific one(int*), you need to cast it. i.e. int* can not point to void*(since void* is superset)

so cast it… j = (int*)k will work.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.