Doubt in Question No. 8

The code in question number 8 , I think it will get compiled.
Because both the pointer variables should contain addresses of an adjacent bucket which contains a garbage value.

Hence i compiled and run the code in ide and it did correctly.
The output were 2 different addresses.

But the answer given in the solution is “NO” ,i.e it will not compile,(though it did correctly).
So,I want to get clarified.

Hello @sayangosw you must have done somechanges in the code because int cant handle the address.
you have to handle it by either tyoecasting it or changing the data type:
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.

Ok,I understood the matter

@sayangosw you can mark this doubt as resolved.
Happy Learning!!