This blog is under construction

Saturday, 5 October 2013

Advantages and disadvantages of pointers in c

Benefits(use) of pointers in c:

  • Pointers provide direct access to memory
  • Pointers provide a way to return more than one value to the functions
  • Reduces the storage space and complexity of the program
  • Reduces the execution time of the program
  • Provides an alternate way to access array elements
  • 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.
Basically, pointer bugs are difficult to debug.  Its programmers responsibility to use pointers effectively and correctly.

25 comments:

  1. This content is very much helpful for me.. Thank you :)

    ReplyDelete
  2. I have a doubt. As mentioned in the dis-adv if the Pointer are slower than the normal variables then how can they reduce the execution time ?

    Pardon me if the doubt is lame. I am new to C Language.

    ReplyDelete
  3. Really an great help.....
    & i like your blogspot name "see programming" :)

    ReplyDelete
  4. Yes, I have the same view with "Unknown".Could you explain to us, how pointer can reduce the execution time. Im new also in programming c

    ReplyDelete
  5. Yes, I have the same view with "Unknown".Could you explain to us, how pointer can reduce the execution time. Im new also in programming c

    ReplyDelete
  6. I have the same doubt regarding to execution time reduction because of pointer.

    ReplyDelete
  7. how can i insert unlimited records in programms of c++ using pointer and array

    ReplyDelete
  8. Even I have the same doubt as unknow have.........

    ReplyDelete
  9. because it's a indirect access to the variable so it's slower then normal variable

    ReplyDelete
  10. How to implement linklist,tree and graph without Pointer?

    ReplyDelete
  11. Thank you much.this is very helpful.

    ReplyDelete
  12. Thank you much.this is very helpful.

    ReplyDelete
  13. Main drawback of pointer is it doesn't provides security. That's y pointers are committed in oops

    ReplyDelete
  14. Main drawback of pointer is it doesn't provides security. That's y pointers are committed in oops

    ReplyDelete
  15. let us assume the chess board as memory,give the numbers from 0 to 63 in boxes of board.assume each box as 1 byte,now you declare the int pointer variable it will take 4 bytes,it occupies the address from 0 th box to 3 rd box,so the address of the integer variable is 0-3.similarly for every variable we have a particular address.this will provide to access memory easily and through address we can easily find the location reach destination fastly, similarly here also execution will take less time,just image these things in real world you will get an idea.

    ReplyDelete
  16. Thanks admin can u share your email id with me

    ReplyDelete