Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

pointers

cornercorner Posts: 21Member
I dont get the point of pointers how do you use and hoew do you know when to use them
«1

Comments

  • LundinLundin Posts: 3,711Member
    : I dont get the point of pointers how do you use and hoew do you know when to use them
    :


    http://c-faq.com/
  • bilderbikkelbilderbikkel Posts: 754Member
    : I dont get the point of pointers how do you use and hoew do you know when to use them
    You can use pointers fro
    - Dynamic allocation of classes, but prefer std::auto_ptr
    - Dynamic allocation of arrays, but prefer std::vector
    - Polymorphism
    For retionale and references, see
    www.codepedia.com/1/CppPointer
    www.codepedia.com/1/CppAutoPtr
    www.codepedia.com/1/CppVector
    www.codepedia.com/1/CppPolymorphism

    See ya,
    bilderbikkel

  • FDracheFDrache Posts: 64Member
    : I dont get the point of pointers how do you use and hoew do you know when to use them
    :
    Generally, you prefer to pass data with a pointer when it's
    - more than 8 bytes
    - of variable length, like text
    A pointer needs only 4 bytes which goes faster than copying the whole data. Another important aspect: The data stays on one place. Making several copies of it could be contradictory.

    The disadvantage of pointers are the lack of transparency and that they could point to something else than expected or to nothing as long as they are not initialised.

    Many C(++) programmers use pointers for functions to give more than 1 return value back. This has 2 disadvantages: 1. You cannot see well what is input and what is output. 2. You cannot see which side fournishes the memory space (in most cases the caller).


  • shaolin007shaolin007 Posts: 1,018Member
    : I dont get the point of pointers how do you use and hoew do you know when to use them
    :
    [green]
    Thats a question with a big answer. On the low level, you use pointers all the time but it is transparent to you because the high level language generates that code for you. A cpu has registers which can hold only so much data at one time. To overcome this, pointers are used to point to a location of memory where the data is stored. That is one example. On the high level, pointers are used in a similiar fashion. They can point to files, arrays, data types, functions, and ect.. This makes the process of accessing and transfering data easier. To know more, I would suggest clicking on some of the links given by the others.
    [/green]

  • cornercorner Posts: 21Member
    : : I dont get the point of pointers how do you use and hoew do you know when to use them
    : :
    : Generally, you prefer to pass data with a pointer when it's
    : - more than 8 bytes
    : - of variable length, like text
    : A pointer needs only 4 bytes which goes faster than copying the whole data. Another important aspect: The data stays on one place. Making several copies of it could be contradictory.
    :
    : The disadvantage of pointers are the lack of transparency and that they could point to something else than expected or to nothing as long as they are not initialised.
    :
    : Many C(++) programmers use pointers for functions to give more than 1 return value back. This has 2 disadvantages: 1. You cannot see well what is input and what is output. 2. You cannot see which side fournishes the memory space (in most cases the caller).
    :
    :
    :
    CORNER

    So what you are saying is that i can write a programme that most usualy has pointers and exclude pointers. Even though it would make my job a bit harder
  • MojojojoMojojojo Posts: 17Member
    : I dont get the point of pointers how do you use and hoew do you know when to use them
    :

    Pointers are the MEAT of C/C++. I guess you have gone vegetarian!
  • Gregry2Gregry2 Posts: 607Member
    : : : I dont get the point of pointers how do you use and hoew do you know when to use them
    : : :
    : : Generally, you prefer to pass data with a pointer when it's
    : : - more than 8 bytes
    : : - of variable length, like text
    : : A pointer needs only 4 bytes which goes faster than copying the whole data. Another important aspect: The data stays on one place. Making several copies of it could be contradictory.
    : :
    : : The disadvantage of pointers are the lack of transparency and that they could point to something else than expected or to nothing as long as they are not initialised.
    : :
    : : Many C(++) programmers use pointers for functions to give more than 1 return value back. This has 2 disadvantages: 1. You cannot see well what is input and what is output. 2. You cannot see which side fournishes the memory space (in most cases the caller).
    : :
    : :
    : :
    : CORNER
    :
    : So what you are saying is that i can write a programme that most usualy has pointers and exclude pointers. Even though it would make my job a bit harder
    :

    IMO, its probably near impossible to write anything important or useful without directly using pointers in C/C++. I mean, the Win32 API, no, probably ever API or library imaginable uses pointers in one way or another. Only some printf() program could go without it.

    {2}rIng
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [b][red]This message was edited by AsmGuru62 at 2006-10-27 4:15:4[/red][/b][hr]
    : IMO, its probably near impossible to write anything important or useful without directly using pointers in C/C++. I mean, the Win32 API, no, probably ever API or library imaginable uses pointers in one way or another. Only some printf() program could go without it.
    :
    : {2}rIng
    :
    [code]
    printf ("Hello!");
    |
    +--- That is a hidden pointer!
    [/code]:-)



  • Gregry2Gregry2 Posts: 607Member
    : [code]
    : printf ("Hello!");
    : |
    : +--- That is a hidden pointer!
    : [/code]:-)

    Oh ho yeah! Screw it, some expression only program then would, ya wouldn't need to do anything with pointers...or rather do anything special at all...*chuckle*

    To the original poster:
    you said using pointers is a more difficult approach, or at least you implied it in a way. It may seem so at first, but with practice, it will eventually become easier to use.

    {2}rIng
  • cornercorner Posts: 21Member
    : : [code]
    : : printf ("Hello!");
    : : |
    : : +--- That is a hidden pointer!
    : : [/code]:-)
    :
    : Oh ho yeah! Screw it, some expression only program then would, ya wouldn't need to do anything with pointers...or rather do anything special at all...*chuckle*
    :
    : To the original poster:
    : you said using pointers is a more difficult approach, or at least you implied it in a way. It may seem so at first, but with practice, it will eventually become easier to use.
    :
    : {2}rIng
    :


    Are you willing to supply the practice

«1
Sign In or Register to comment.