Test Series - cpp

Test Number 18/102

Q: The void pointer can point to which type of objects?
A. int
B. float
C. double
D. all of the mentioned
Solution: Because it doesn’t know the type of object it is pointing to, So it can point to all objects.
Q: When does the void pointer can be dereferenced?
A. when it doesn’t point to any value
B. when it cast to another type of object
C. using delete keyword
D. using shift keyword
Solution: By casting the pointer to another data type, it can be dereferenced from the void pointer.
Q: The pointer can point to any variable that is not declared with which of these?
A. const
B. volatile
C. both const & volatile
D. static
Solution: Pointer can point to any variable that is not declared with const & volatile.
Q: A void pointer cannot point to which of these?
A. methods in c++
B. class member in c++
C. methods & class member in c++
D. none of the mentioned
Solution: A void pointer can point to methods & class member in c++.
Q: What we can’t do on a void pointer?
A. pointer arithmetic
B. pointer functions
C. pointer objects
D. pointer functions & objects
Solution: Because the void pointer is used to cast the variables only, So pointer arithmetic can’t be done in a void pointer.
Q: The data elements in the structure are also known as what?
A. objects
B. members
C. data
D. objects & data
Solution: Variables declared inside a class are called as data elements or data members.
Q: What will happen when the structure is declared?
A. it will not allocate any memory
B. it will allocate the memory
C. it will be declared and initialized
D. it will be declared
Solution: While the structure is declared, it will not be initialized, So it will not allocate any memory.
Q: The declaration of the structure is also called as?
A. structure creator
B. structure signifier
C. structure specifier
D. structure creator & signifier
Solution: The structure declaration with open and close braces and with a semicolon is also called structure specifier.
Q: Which of the following is a properly defined structure?
A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};
Solution: option struct {int a;} is not correct because name of structure and ;(after declaration) are missing. In option struct a_struct {int a;} ; is missing. In option struct a_struct int a; {} are missing.
Q: Which of the following accesses a variable in structure *b?
A. b->var;
B. b.var;
C. b-var;
D. b>var;
Solution: Because arrow operator(->) is used to access members of structure pointer whereas dot operator(.) is used to access normal structure variables.

You Have Score    /10