Exforsys

Online Training

array & dynamic memory allocation

This is a discussion on array & dynamic memory allocation within the C and C++ forums, part of the Programming Talk category; You can use array and pointer equivalently. How can you handle array dynamically?...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-28-2006, 02:42 AM
Junior Member
 
Join Date: Nov 2006
Posts: 2
usha ranawade is on a distinguished road
Thumbs up array & dynamic memory allocation

You can use array and pointer equivalently. How can you handle array dynamically?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-05-2006, 06:36 AM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
Dynamic array allocation is actually a combination of pointers and dynamic memory allocation.While static arrays are declared prior to runtime and are reserved in stack memory, dynamic arrays are created in the heap and released from the heap and in C++ this is handled by using the new[ ] and delete[ ] operators.

int *example;

This C++ statement simply declares an integer pointer. A pointer is a variable that holds a memory address. Declaring a pointer doesn't reserve any memory for the array and that will be accomplished with new[ ].

The following C++ statement requests 15 integer-sized elements be reserved in the heap with the first element address being assigned to the pointer example:

example = new int[15];

The new[ ] operator is requesting 15 integer elements from the heap.Dynamic array allocation is nice because the size of the array can be determined at runtime and then used with the new[ ] operator to reserve the space in the heap.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Array Internals Charith C and C++ 2 04-07-2007 09:33 AM
C Programming - Dynamic Memory allocation lokeshm C and C++ 2 06-17-2006 08:10 PM
AMI BIOS Beep Codes lokeshm Chit-Chat 2 06-13-2006 08:48 PM
Visual Basic : Determining the size of a VB dynamic array techguru Visual Basic Tutorials 0 08-29-2005 01:27 PM
shared memory and semaphores itzsug C and C++ 1 08-24-2004 05:42 PM


All times are GMT -4. The time now is 05:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.