Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Dynamically Allocated Array

This is a discussion on Dynamically Allocated Array within the C and C++ forums, part of the Programming Talk category; I have knowledge of array concepts in programming language .But what is dynamically allocated arrays in C programming language. Can ...

  1. #1
    Rahulbatra is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124

    Dynamically Allocated Array

    I have knowledge of array concepts in programming language .But what is dynamically allocated arrays in C programming language. Can someone provide knowledge on this?


  2. #2
    vamsy_569 is offline Junior Member Array
    Join Date
    Mar 2007
    Answers
    3
    if an array is created at runtime it is known as dynamically created array
    we can create array dynamically by using malloc() and calloc()
    we prefer to create array dynamically becoz there are three problems with
    static memory allocation
    consider this int a[10]
    1) memory wastage
    if we store only 5 values the remaining memory of 6 integers is
    wasted
    2)overflow
    here we can store only 11 integers if we try to store 12th integer
    it raises overflow becoz how can we store 12 integers if we created array
    only for 11 integers
    3)array size cannot be variable
    int n=7;
    int a[n]; // error
    becoz the value 7 is stored in 'n' at runtime but we are creating arrayat
    compilation time.at compilation time 'n' is not defined


  3. #3
    vamsy_569 is offline Junior Member Array
    Join Date
    Mar 2007
    Answers
    3
    the syntax for malloc is
    ptr = (typecasting)malloc(sizeof(datatype));

    if u have any doubt please dont hesitate to ask


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...