Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

question on array in c++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick - 23 May 2006 17:25 GMT
Hi, I have a question about array in vc++.  I initialized an array from 0 to
480 using memset.  and I just realized that in one instance of my code i am
putting a value in array position -2, which the array does not have.  will
this action cause a problem if i try to use delete to deallocate the array
from memory??  thank you in advance! help is greatly appreciated!
Doug Harrison [MVP] - 23 May 2006 17:40 GMT
>Hi, I have a question about array in vc++.  I initialized an array from 0 to
>480 using memset.  and I just realized that in one instance of my code i am
>putting a value in array position -2, which the array does not have.  will
>this action cause a problem if i try to use delete to deallocate the array
>from memory??  thank you in advance! help is greatly appreciated!

Writing outside an array will corrupt whatever object is stored there, if
any. It could be part of the heap's internal fields, it could be another
object, it could be unallocated memory, or it could be inaccessible memory,
in which case, you'll get an access violation. So don't ever write outside
an array's storage.

That said, if you have a pointer p to an element inside an array, and that
element is at index 2 or beyond, then p[-2] is a valid way to refer to the
item 2 positions before *p.

Signature

Doug Harrison
Visual C++ MVP


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.