CPP Pointers MCQ
Cpp MCQ(1) Which of the following is correct syntax to cast void pointer into int using C++ ?
A) static_cast<int*>
B) static_cast<*int>
C) *static_cast<int>
D) *static_cast<int*>
Explanation
static_cast<int*>(ptr) is the proper way to cast void pointer into int. We can cast void pointer in other data types in the same way.
(2) Which of the following is considered as critical type of pointer ?
A) Void
B) NULL
C) Wild
D) Dangling
Explanation
Wild pointer is considered as critical because it may points to an un authorized memory location by default.
(3) How many bytes occupied by a void pointer in memory
A) 2
B) 4
C) 8
D) 16
Explanation
This normally depends on compiler being used. But most commonly void pointer occupy 8 bytes in memory.
(4) Which of the following is called dereference operator ?
A) *
B) &
C) "
D) #
Explanation
* asterisk is called dereference operator in C++. It is used to declare pointer variable. It is also used with pointer variable to access the value of stored address.
(5) Which of the following is called address operator?
A) &
B) %
C) *
D) @
Explanation
Ampersand is called address operator. It can be used to get address value of any variable. After getting address we can save it in pointer.
(6) Which of the following operator is used while pointers declaration?
A) *
B) @
C) &
D) %
Explanation
Asterisk operator is used along with dara type for pointers declaration. If we use asterisk operator with data type name then all coming variable in this declaration statement will be declared as pointets. We can also use asterisk with individual variables in declaration statement.
(7) Which of the following type data is stored in pointers?
A) Decimal
B) Octal
C) Binary
D) Hexadecimal
Explanation
Pointers are used to store the memory addresses. And the memory addresses are in hexadecimal format. So that pointers store hexadecimal data.
(8) Pointers are used to store which of the following?
A) Data
B) Address
C) Other variable
D) None
Explanation
Pointer variables are used to store address of other variables of same type. Means to store address of float type variable we have to declare float type pointer.
.