1.

Explain pointers in C++.

Answer»

A variable that holds the address of another variable of the same data type can be called a pointer. Pointers can be created for any data type or user-defined datatypes LIKE class, structure, etc. It allows variable passing by REFERENCES using the address. For example:

int x = 25;int *ptr = &x;cout << ptr;

Here, ptr will store the address of x. That means the address of x is the ptr value.
Using *ptr, we can obtain the value STORED in the address referenced by ptr(i.e., 25). *ptr is known as dereference operator.

Uses of pointers:

  • To point a variable PRESENT inside the memory.
  • To store addresses of dynamically allocated memory blocks.


Discussion

No Comment Found