Exforsys

Online Training

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 ...


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

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-26-2007, 04:39 PM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-30-2007, 02:57 AM
Junior Member
 
Join Date: Mar 2007
Posts: 3
vamsy_569 is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-30-2007, 02:59 AM
Junior Member
 
Join Date: Mar 2007
Posts: 3
vamsy_569 is on a distinguished road
the syntax for malloc is
ptr = (typecasting)malloc(sizeof(datatype));

if u have any doubt please dont hesitate to ask
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
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-15-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-01-2004 07:01 AM
comp.lang.c FAQ list Table of Contents Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 05-15-2004 07:00 AM


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


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