Pointers Interview Questions

    Question 1C++ Pointer Declaration

    Which of the following is the correct way to declare a pointer to an integer in C++?

    Question 2C++ Guess the Output – Dereferencing

    What will this code print?

    #include <iostream> using namespace std; int main() { int x = 10; int *ptr = &x; cout << *ptr; return 0; }

    Question 3C++ Address-of Operator

    What does the & operator do in the context of pointers?

    Question 4C++ Guess the Output – Pointer and Variable

    What will be the output of this program?

    #include <iostream> using namespace std; int main() { int num = 25; int *p = # cout << &num << " " << p; return 0; }

    Question 5C++ Null Pointer

    How can we assign a null value to a pointer in modern C++?

    Question 6C++ Guess the Output – Pointer Arithmetic

    What will be the output of this program?

    #include <iostream> using namespace std; int main() { int arr[3] = {10, 20, 30}; int *p = arr; cout << *(p + 2); return 0; }

    Question 7C++ Pointer to Pointer

    What is the correct way to declare a pointer to a pointer of an integer?

    Question 8C++ Guess the Output – Double Pointer

    What will the following program print?

    #include <iostream> using namespace std; int main() { int val = 50; int *p = &val; int **pp = &p; cout << **pp; return 0; }

    Question 9C++ Pointers and Arrays

    Which of the following statements is true about arrays and pointers in C++?

    Question 10C++ Guess the Output – Pointer Size

    What will the output of the following program be (on a 64-bit system)?

    #include <iostream> using namespace std; int main() { int *p; double *q; cout << sizeof(p) << " " << sizeof(q); return 0; }