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

Thread: pointer issues

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    4

    Unhappy pointer issues

    Hello, I am running into trouble with (what I thought would be) a simple algorithm that takes in an int array, and returns the number of elements in the array. It seems to work with arrays with only one digit, but does not work with arrays with int values >9 or <-9 . I was under the impression that pointer arithmetic takes into account the size of the elements in the array, but no matter what changes I make, arrays with multiple digit values always seems to run off the array with this function. Does anyone have any ideas on what I might be doing wrong?

    int Alg::getSize(int array[])
    {
    int size = 0;
    int* ptr = &array[0];

    while ((*ptr) != '\0')
    {
    size++;
    ptr++;
    }

    return size;
    }
    Last edited by Rahl; February 4th, 2009 at 07:54 PM. Reason: clarity

Tags for this 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
  •  





Click Here to Expand Forum to Full Width

Featured