Site icon T4Tutorials.com

Pointers Solved MCQs Questions Answers

1. What is the output of the following code?
int a = 10;
int *p = &a;
cout << *p;

(A) 0


(B) Address of a


(C) 10


(D) Compilation error



2. Which of the following is the correct syntax to declare a pointer to an integer?

(A) int ptr;


(B) int *ptr;


(C) ptr int*;


(D) int& ptr;



3. What will happen if you try to dereference a null pointer?

(A) Runtime error


(B) Compilation error


(C) Prints 0


(D) Prints garbage value



4. What is the output of this code?
int a = 5, b = 10;
int *p = &a;
*p = b;
cout << a;

(A) 5


(B) 10


(C) Compilation error


(D) Garbage value



5. What does the & operator do in pointer context?

(A) Returns the value stored at pointer


(B) Dereferences the pointer


(C) Declares a reference


(D) Returns the address of a variable



6. Which of the following will correctly access the value pointed to by pointer p?
int *p;

(A) &p


(B) *p


(C) p


(D) >p



7. What will the following code print?
int x = 20;
int *p = &x;
*p = *p + 5;
cout << x;

(A) 20


(B) 25


(C) Compilation error


(D) Garbage value



8. Which of the following statements is correct about pointers?

(A) Pointer must point to a variable of same type


(B) Pointer can point to any variable of any type


(C) Pointer stores the value of the variable


(D) Pointer cannot point to another pointer



9. What is the output of this code?
int a = 3, b = 4;
int *p = &a, *q = &b;
*p = *p + *q;
cout << a << " " << b;

(A) 7 4


(B) 3 4


(C) 3 7


(D) Compilation error



10. What happens if you increment a pointer?

(A) Pointer value increases by 1


(B) Compilation error


(C) Pointer points to next memory of same type


(D) Pointer value decreases



11. What is wrong with this code?
int *p;
*p = 5;

(A) Nothing


(B) Dereferencing uninitialized pointer


(C) Syntax error


(D) p should be int



12. How can you declare a pointer to a pointer?

(A) int **ptr;


(B) int ptr2;


(C) int &ptr;


(D) int *ptr2;



13. What is the output of this code?
int arr[] = {1,2,3};
int *p = arr;
cout << *(p+1);

(A) 1


(B) Garbage


(C) 3


(D) 2



14. Which statement is correct?

(A) Pointer arithmetic depends on size of type


(B) Pointer arithmetic is always +1


(C) Pointers cannot be compared


(D) Pointer arithmetic is undefined



15. What is the output?
int a = 10;
int *p = &a;
cout << p;

(A) 10


(B) Address of a


(C) Compilation error


(D) Null



16. What will this code output?
int x = 5;
int *p = &x;
int **q = &p;
**q = 15;
cout << x;

(A) 5


(B) Garbage


(C) Compilation error


(D) 15



17. Which is the correct way to allocate memory dynamically for an integer?

(A) int *p = new int;


(B) int p = new int;


(C) int p = int*;


(D) int *p = malloc(sizeof(int));



18. What is wrong in this code?
int *p = NULL;
cout << *p;

(A) Nothing


(B) Dereferencing null pointer


(C) Syntax error


(D) Pointer should be int



19. Output of this code?
int a = 3;
int *p = &a;
int *q = p;
*q = 7;
cout << a;

(A) 7


(B) 3


(C) Compilation error


(D) Garbage



20. Which statement is true about pointers and arrays?

(A) Array name is a constant pointer


(B) Arrays cannot be accessed using pointers


(C) Pointer cannot point to array element


(D) Array name stores the value of first element



 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs

 

Programming C Plus Plus MCQs Homepage

Low-level and high-level languages MCQs

Procedural and non Procedural languages MCQs

C++ STANDARD LIBRARY MCQs

 Array  MCQs 

Arrays MCQs 2

Pointers Solved MCQs

Inline Function MCQs – C++

Top 50 Programming  C++ MCQs 

MCQs of introduction to programming

Past Papers 2022 C++ MCQs

Past Papers 2021 C++ MCQs

Past Papers 2020 C++ MCQs

Past Papers 2019 C++ MCQs

Highly Recommended C++  Important MCQs with Explanation

OOP

OOP intro & examples MCQs

Classes and Inheritance MCQs

Friend Function MCQs

Virtual Function MCQs

Polymorphism MCQs

Polymorphism MCQs 2

shamil memory table

Computer Science Repeated MCQs Book Download

Exit mobile version