Doubt in mcq Q8

Q­8 Would the following program compile?
#include
using namespace std;
int main() {
int a=10, *j; void *k; j=k=&a; j++;
k++; cout<<j<<k; return 0;
}
Would the following program compile?
A) Yes
B) No

i didnt undertood why answer is No?? it compiles so why answer is no?

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.