1. What is a Pointer in C++?

A pointer is a variable that stores the memory address of another variable.
It allows direct access and manipulation of memory.

2. How do you declare a pointer?

A pointer is declared using the * symbol.
Example: int *ptr;
Here ptr is a pointer to an integer.

3. What is the use of the address-of (&) operator?

The & operator returns the memory address of a variable.
Example: int a = 10; int *ptr = &a;

4. What is dereferencing?

Dereferencing means accessing the value stored at the memory address
using the * operator.

5. What is a NULL pointer?

A NULL pointer does not point to any valid memory location.
In modern C++, nullptr is preferred over NULL.

6. What is nullptr?

nullptr is a keyword introduced in C++11 that represents a null pointer constant.

7. What is a Wild Pointer?

A pointer that is declared but not initialized is called a wild pointer.
It may point to random memory location.

8. What is a Dangling Pointer?

A dangling pointer points to memory that has already been freed.

9. What is Void Pointer?

A void pointer (void*) can store the address of any data type.
But it must be typecast before dereferencing.

10. What is Pointer Arithmetic?

Pointer arithmetic includes increment (++), decrement (–), addition,
and subtraction operations on pointers.

11. What is Double Pointer?

A double pointer stores the address of another pointer.
Example: int **ptr;

12. What is Dynamic Memory Allocation?

Memory allocation at runtime using new operator.
Example: int *ptr = new int;

13. What is the difference between new and malloc?

new is an operator in C++ that calls constructor.
malloc is a C function that does not call constructor.

14. What is delete operator?

delete is used to free memory allocated using new.
Example: delete ptr;

15. What is memory leak?

Memory leak occurs when dynamically allocated memory is not freed.

16. What is Heap memory?

Heap memory is used for dynamic memory allocation.
It is managed manually using new and delete.

17. What is Stack memory?

Stack memory stores local variables and function calls.
It is automatically managed.

18. Difference between Stack and Heap?

Stack is faster and automatically managed.
Heap is slower and manually managed.

19. What is Smart Pointer?

Smart pointers are objects that manage dynamically allocated memory
automatically to prevent memory leaks.

20. Types of Smart Pointers?

unique_ptr, shared_ptr, and weak_ptr.

21. What is unique_ptr?

unique_ptr owns a resource exclusively and cannot be copied.

22. What is shared_ptr?

shared_ptr allows multiple pointers to share ownership of same resource.

23. What is weak_ptr?

weak_ptr is used with shared_ptr to prevent circular reference.

24. What is RAII?

Resource Acquisition Is Initialization is a concept where
resource allocation and deallocation are tied to object lifetime.

25. What is placement new?

Placement new allows constructing object at a specific memory location.

26. What is const pointer?

A pointer whose address cannot be changed.
Example: int *const ptr;

27. What is pointer to const?

Pointer that cannot modify value it points to.
Example: const int *ptr;

28. What is function pointer?

A pointer that stores the address of a function.

29. What is array of pointers?

An array where each element is a pointer.

30. What is pointer to array?

A pointer that points to entire array.

31. What is Memory Fragmentation?

Memory fragmentation occurs when free memory is divided into small blocks
over time, making it difficult to allocate large continuous memory blocks.
It reduces system performance and efficient memory utilization.

32. What is Memory Alignment?

Memory alignment refers to arranging data in memory according to
the system architecture requirements. Proper alignment improves
performance and avoids hardware exceptions.

33. What is Virtual Memory?

Virtual memory is a memory management technique where the operating system
uses disk space to extend RAM. It allows programs to use more memory
than physically available.

34. What is a Segmentation Fault?

A segmentation fault occurs when a program tries to access memory
that it is not allowed to access, such as dereferencing a null or
dangling pointer.

35. What is Buffer Overflow?

Buffer overflow happens when data exceeds the allocated buffer size
and overwrites adjacent memory, leading to crashes or security issues.

36. What is Shallow Copy?

Shallow copy copies only the pointer values, not the actual data.
Both objects share the same memory location.

37. What is Deep Copy?

Deep copy duplicates both the pointer and the data it points to.
Each object has its own separate memory.

38. What is Move Semantics?

Move semantics transfers ownership of resources from one object
to another instead of copying, improving performance.

39. What is Copy Elision?

Copy elision is a compiler optimization that eliminates unnecessary
copy constructor calls to improve performance.

40. What are Custom Allocators?

Custom allocators allow developers to control memory allocation
strategy, often used in performance-critical applications.

41. What is Garbage Collection?

Garbage collection is automatic memory management that frees unused memory.
C++ does not have built-in garbage collection; memory is manually managed.

42. What is Memory Leak Detection?

Memory leak detection involves using tools like Valgrind or sanitizers
to detect unfreed memory allocations.

43. What is Heap Corruption?

Heap corruption occurs when memory outside allocated heap boundaries
is modified, causing undefined behavior.

44. What is Stack Overflow?

Stack overflow happens when too many recursive function calls or
large local variables exceed stack memory limit.

45. What is Circular Reference in shared_ptr?

Circular reference occurs when two shared_ptr objects reference each other,
preventing memory from being released. It is solved using weak_ptr.

46. What is Overloading new Operator?

The new operator can be overloaded to customize memory allocation behavior.

47. What is Overloading delete Operator?

The delete operator can be overloaded to customize memory deallocation.

48. What is Memory Pool?

A memory pool is a pre-allocated block of memory used to manage
allocations efficiently and reduce fragmentation.

49. What are Best Practices to Avoid Memory Leaks?

Initialize pointers, use smart pointers, follow RAII principle,
and ensure delete is called for every new allocation.

50. Why are Smart Pointers Preferred in Modern C++?

Smart pointers automatically manage memory and prevent leaks,
dangling pointers, and ownership issues, making code safer and cleaner.

📢 Join Our WhatsApp Channel

💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.

👉 Join WhatsApp Now

📢 Join Our Telegram Channel

💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!

👉 Join Telegram

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 - 2025 itfreesource.com

Enable Notifications OK No thanks