Thread: allocation and reallocation of memory dynamically of an integer array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    allocation and reallocation of memory dynamically of an integer array

    Write a program in which you have to:
    1. Dynamically allocate an array of integers.
    2. Take array size as input from user and allocate memory according to this size.
    3. Take values of array elements as an input from user.
    4. Print all array values.
    5. In this step; double the previous array size (taken in step 2) and reallocate memory for the array according to new array size. For example if user provided array size is 4; now it will become 8, i.e. allocate memory for array having size 8.

    6. Now again take values for second half of the array as an input from the user to fill the increased size of an array.(You have already taken the values of first half of the array elements in step 3, now take values for remaining elements i.e. Second half).
    7. Print all values of the array.
    8. Also confirm that first half values of array are same in both printout statements (step 3 and step 7).


    Sample Output
    Program to dynamically Allocates an array of integers.
    Enter the size of the array: 4
    Enter a value: 1
    Enter a value: 2
    Enter a value: 3
    Enter a value: 4


    The elements of the array are:
    1 2 3 4

    Enter the elements in the array after reallocation:
    Enter a value: 5
    Enter a value: 6
    Enter a value: 7
    Enter a value: 8

    1 2 3 4 5 6 7 8
    Last edited by zamir; 05-26-2009 at 04:58 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 08:36 AM
  2. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  3. Dynamic array allocation and reallocation
    By purple in forum C Programming
    Replies: 13
    Last Post: 08-01-2002, 11:48 AM