Multiple choice technology programming languages

void vp; char c; int i=20; float f=30.00; pick the line which will cause an error in a C++ compiler

  1. vp=&f;

  2. c=(char*)&i;

  3. c=vp;

  4. *i++;

  5. f++;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In C++, assigning a void* to a char* without an explicit cast is not allowed. While this is valid in C (where void* can be implicitly converted to any other pointer type), C++ requires an explicit cast: c = (char*)vp; or c = static_cast(vp);. The other assignments are valid - void* can receive any pointer, and casts between pointer types are allowed.