CPP

CPP

Pointer to Void has 10 Questions

Void pointer can point to which type of objects?

int
float
double
all of the mentioned
When does the void pointer can be dereferenced?

when it doesn't point to any value
when it cast to another type of object
using delete keyword
none of the mentioned
The pointer can point to any variable that is not declared with which of these?

const
volatile
both a & b
static
A void pointer cannot point to which of these?

methods in c++
class member in c++
all of the mentioned
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int func(void *Ptr);
  4.     int main()
  5.     {
  6.         char *Str = "abcdefghij";
  7.         func(Str);
  8.         return 0;
  9.     }
  10.     int func(void *Ptr)
  11.     {
  12.         cout << Ptr;
  13.         return 0;
  14.     }

abcdefghij
address of string "abcdefghij"?
compile time error
runtime error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int *p;
  6.         void *vp;
  7.         if (vp == p);
  8.             cout << "equal";
  9.         return 0;
  10.     }

equal
no output
compile error
runtime error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i;
  6.         char c;
  7.         void *data;
  8.         i = 2;
  9.         c = 'd';
  10.         data = &i;
  11.         cout << "the data points to the integer value" << data;
  12.         data = &c;
  13.         cout << "the data now points to the character" << data;
  14.         return 0;
  15.     }

2d
two memory addresses
both of the mentioned
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int n = 5;
  6.         void *p = &n;
  7.         int *pi = static_cast<int*>(p);
  8.         cout << *pi << endl;
  9.         return 0;
  10.     }

5
6
compile time error
runtime error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5, c;
  6.         void *p = &a;
  7.         double b = 3.14;
  8.         p = &b;
  9.         c = a + b;
  10.         cout << c << '\n' << p;
  11.         return 0;
  12.     }

8, memory address
8.14
memory address
none of the mentioned
What we can't do on a void pointer?

pointer arithemetic
pointer functions
both of the mentioned
none of the mentioned