1. Which is used to tell the computer that where a pointer is pointing to?
A. dereference
B. reference
C. heap operations
D. binary operations
Answer: A
Explanation:
dereference is used to tell the computer where a pointer is pointing to it.
2. Which is used to do the dereferencing?
A. pointer without asterix
B. value without asterix
C. pointer with asterix
D. value with asterix
Answer: C
Explanation:
Dereferencing is using a pointer with asterix. For example, *(abC..
3. Pick out the correct option.
A. References automatically dereference without needing an extra character
B. References automatically dereference with an extra character
C. Reference will not dereference
D. Reference automatically dereference with extra space and character
Answer: A
Explanation:
References automatically dereference without needing an extra character.
4. What will be the output of the following C++ code?
#include
using namespace std;
int main()
{
int a, b;
int* c;
c = &a;
a = 200;
b = 200;
*c = 100;
b = *c;
cout << *c << " " << b;
return 0;
}
A. 100 200
B. 100 0
C. 200 200
D. 100 100
Answer: D
Explanation:
In this program, We are making the assignments and invoking the both b and c values as 100 by dereference operator.
5. What will be the output of the following C++ code?
#include
using namespace std;
int main()
{
int x;
int *p;
x = 5;
p = &x;
cout << *p;
return 0;
}
A. 5
B. 10
C. memory address
D. 15
Answer: A
Explanation:
In this program, we are copying the memory location of x into p and then printing the value in the address.
6. What will be the output of the following C++ code?
#include
using namespace std;
int main ()
{
int a;
int * ptr_b;
int ** ptr_c;
a = 1;
ptr_b = &a;
ptr_c = &ptr_b;
cout << a << "\n";
cout << *ptr_b << "\n";
cout << *ptr_c << "\n";
cout << **ptr_c << "\n";
return 0;
}
A.
1
1
0xbffc9924
1
B.
1
1
1
0xbffc9924
C.
1
0xbffc9924
1
&1
D. 0xbffc9924
Answer: A
Explanation:
In this program, We are printing the values and memory address by using the pointer and dereference operator.
7. What will be the output of the following C++ code?
#include
using namespace std;
int main()
{
int x = 9;
int* p = &x;
cout << sizeof(p);
return 0;
}
A. 4
B. 2
C. Depends on compiler
D. 8
Answer: C
Explanation:
The size of a data type mainly depends on compiler only.
8. What will be the output of the following C++ code?
#include
using namespace std;
int main()
{
double arr[] = {5.0, 6.0, 7.0, 8.0};
double *p = (arr+2);
cout << *p << endl;
cout << arr << endl;
cout << *(arr+3) << endl;
cout << *(arr) << endl;
cout << *arr+9 << endl;
return 0;
}
A.
7
0xbf99fc98
8
5
14
B.
7
8
0xbf99fc98
5
14
C. 0xbf99fc98
D. 14
Answer: A
Explanation:
In this program, We are printing the values that are pointed by pointer and also the dereference operator.
9. What does the dereference operator will return?
A. rvalue equivalent to the value at the pointer address
B. lvalue equivalent to the value at the pointer address
C. it will return nothing
D. it will return boolean values
Answer: B
Explanation:
It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address.
10. Pick out the correct statement.
A. the null pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to null
B. the null pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to the memory address
C. rvalue equivalent to the value at the pointer address
D. null pointer will not return anything
Answer: A
Explanation:
The null pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to null.