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

Thread: pointers and references

  1. #1
    Join Date
    Dec 2002
    Posts
    49

    pointers and references

    Hi,
    I have char* a[] = {"abc","def"};
    I want to retrieve the addresses of a, a[0], a[0][0],
    how can I do it without using in the sign'[]', only with pointers.

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Code:
    char* array[] = {"abc","def"};
    void* p = array;  // same as -  void* p = &array[0]
    p = *array;       // same as -  p = &array[0][0]

  3. #3
    Join Date
    Dec 2002
    Posts
    49
    and if I want to print the address I just print p?

  4. #4
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Yes.

    Code:
    printf("0x%X", p);

  5. #5
    Join Date
    Dec 2002
    Posts
    49
    10x

  6. #6
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    In addition, you may interested in the following.

    Code:
    p = *(array + 1);   // same as -  p = &array[1][0]

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




On-Demand Webinars (sponsored)