Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problem with pointers and allocation of dynamic 2d array

problem with pointers and allocation of dynamic 2d array

problem with pointers and allocation of dynamic 2d array

Dear all,

I am a new in Borland C++ 6 and I have a problem with pointers(!). I have a project in which i have to allocate a
dynamic 2-dimensional array, perform some image processing functions and then scan again all the values with the
use of a pointer. My code is this:

int i,j,width,height;
float *PP,q;

width=(size of image);
height=(size of image);

float **image = new float*[height];
for (i = 0; i < height; ++i)
     image[i] = new float[width];

/* some image processing*/

for (i = 0; i < height; ++i)

    for (j = 0; j < width; ++j)

Everything is going fine until, at a certain point, an exception is raised in line q=*PP; (where q reads the
value that address PP indicates).

The exception is: Project xxx.exe raised exception class EAccessViolation with message 'Access violation at address
004023C8 in module 'xxx.exe'. Read of address 00C44000'.

At the begining of the second nested 'for', the pointer PP contains the address of the first element of the array 'image'.
Every time the value is read the pointer increments, pointing to the next element of the array.

I have run the program in steps and i have found that the exception is raised when i=83 and j=width-3. All the previous values of
q are read correctly and are exactly the same as those of 'image'.

Why do you believe that this is happening? Why does it run correctly until i=83 and j=width-3?
Is there a problem with the logic that I used?

Thank you all in advance,


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close