pointer confusion ~.~
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: pointer confusion ~.~

  1. #1
    Join Date
    Aug 2010
    Posts
    5

    pointer confusion ~.~

    Hy can somone pls explain me what the type(like int) **name is... i figure that *is a pointer... but what is **?????
    Last edited by sangoku; September 22nd, 2010 at 09:47 AM.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,893

    Re: pointer confusion ~.~

    "ref class"? I don't know what the ref keyword means. Is this native C++?

    Second, I don't see any reason to be using dynamic allocation if you're always going to allocate to the same size anyway....just make the member be
    int stubovi[3][10];
    to begin with. Working with pointers directly in a class or struct definition introduces complications such as the need to define the copy constructor and operator= explicitly.

    Third, the most likely cause of an error on an array access is the index being invalid. What is saStuba?

    Fourth, even if saStuba is a valid index (0,1, or 2 in this case), the type of stubovi[saStuba] will still be int*, so you won't be able to assign to an int.

  3. #3
    Join Date
    May 2010
    Posts
    19

    Re: pointer confusion ~.~

    Quote Originally Posted by sangoku View Post
    Hy can somone pls explain me what the type(like int) **name is... i figure that *is a pointer... but what is **?????
    the double star implies that its a double pointer, and further allocation may be done

    int variable = 3;
    int variable2 = 5;

    Code:
    int **pointer = new int * [variable];
    for (int i=0; i<variable; i++)
    {
    pointer[variable] = new int[variable2];
    }
    Last edited by dchaacke; September 22nd, 2010 at 12:16 PM. Reason: corrected information

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,893

    Re: pointer confusion ~.~

    Quote Originally Posted by dchaacke View Post
    the double star implies that further allocation will be done
    Well no, it only implies it's a pointer which happens to point to another pointer. Often this will indicate further allocation is done, but not always.

  5. #5
    Join Date
    May 2010
    Posts
    19

    Re: pointer confusion ~.~

    Quote Originally Posted by Lindley View Post
    Well no, it only implies it's a pointer which happens to point to another pointer. Often this will indicate further allocation is done, but not always.
    my mistake, i have edited my post.

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,060

    Re: pointer confusion ~.~

    [ Moved thread ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center