Computer Science, asked by Manjot7241, 1 year ago

What is a pointer.its advantages and disadvantages?

Answers

Answered by Anonymous
4
Pointers are used to store and manage the addresses of dynamically allocated blocks of memory. Such blocks are used to store data objects or arrays of objects. Most structured and object-oriented languages provide an area of memory, called the heap or free store, from which objects are dynamically allocated.

Benefits(use) of pointers in c:

Pointers provide direct access to memoryPointers provide a way to return more than one value to the functions
Reduces the storage space and complexity of the programs
Reduces the execution time of the program
Provides an alternate way to access array element
Pointers can be used to pass information back and forth between the calling function and called function.
Pointers allows us to perform dynamic memory allocation and deallocation.Pointers helps us to build complex data structures like linked list, stack, queues, trees, graphs etc.
Pointers allows us to resize the dynamically allocated memory block.
Addresses of objects can be extracted using pointers


Drawbacks of pointers in c:

Uninitialized pointers might cause segmentation fault.
Dynamically allocated block needs to be freed explicitly.
 Otherwise, it would lead to memory leak.
Pointers are slower than normal variables.If pointers are updated with incorrect values, it might lead to memory corruption.



Similar questions