GeekInterview.com
Results 1 to 7 of 7

Advantages of using pointers in C

This is a discussion on Advantages of using pointers in C within the C and C++ forums, part of the Software Development category; pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved pointers basically hold the address of a variable. ...

  1. #1
    dollysinha is offline Junior Member Array
    Join Date
    Dec 2007
    Answers
    2

    Advantages of using pointers in C

    pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved

    pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values


  2. #2
    dollysinha is offline Junior Member Array
    Join Date
    Dec 2007
    Answers
    2

    Re: Advantages of using pointers in C

    pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved

    pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values


  3. #3
    sk_seeker is offline Contributing Member Array
    Join Date
    Dec 2007
    Answers
    48

    Re: Advantages of using pointers in C

    Quote Originally Posted by dollysinha View Post
    pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved

    pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values
    This was an interesting question. This reminded me to keep in touch with the basics: easy to forget them.

    Okay. Here are the advantages of pointers as I see it.
    - Pointers allow you to implement sharing without copying i.e. pass by reference v/s pass by copying. This allows a tremendous advantage when you are passing around big arrays as arguments to functions.
    - Pointers allow modifications by a function that is not the creator of the memory i.e. function A can allocate the memory and function C can modify it, without using globals, which is a no-no for safe programming.
    - Pointers allow us to use dynamic memory allocation.
    - Pointers obviously give us the ability to implement complex data structures like linked lists, trees, etc
    - Pointers allow ease of programming, especially when dealing with strings. This is due to the fact that a pointer increment will move by the size of the pointee i.e. easy coding to increment to the next memory location of an array, without worrying about how many bytes to move for each data type. I.e. a pointer to a char will move the pointer by a byte, pointer to an int, by the size of the int, etc NOTE that this is important because you do not have to worry about the size of the data types which can vary on different architectures.
    - Pointers allow us to resize the data structure whenever needed. For example, if you have an array of size 10, it cannot be resized. But, an array created out of malloc and assigned to a pointer can be resized easily by creating a new memory area through malloc and copying the old contents over. This ability is very important in implementing sparse data structures also.

    Well, that is all I can think of.


  4. #4
    vanamajaya is offline Junior Member Array
    Join Date
    Sep 2008
    Answers
    2

    Re: Advantages of using pointers in C

    how many typs of pointers


  5. #5
    deepasree is offline Banned Array
    Join Date
    Apr 2008
    Answers
    1,913

    Re: Advantages of using pointers in C

    hi friend..

    The topic is vast, you just refer this link to get a clear idea Pointer (computing) - Wikipedia, the free encyclopedia

    Thanks
    Deepasree


  6. #6
    Sushma Mosali is offline Expert Member Array
    Join Date
    Jun 2007
    Answers
    276

    Re: Advantages of using pointers in C

    hi,

    hope this link will help you out Pointers

    Thanks
    Sushma


  7. #7
    sriranga.ch is offline Junior Member Array
    Join Date
    Aug 2008
    Answers
    1

    Re: Advantages of using pointers in C

    Pointer is nothing but a variable which stores the address of another variable.while using the pointer we can store any data type suppose using an array we can able to store particular defined data type only but in pointers we can store any datatype.Its like a reference variable.


    •    Sponsored Ads