
- Forum
- Programming Talk
- C and C++
- Dynamically Allocated Array
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 ...
-
03-26-2007, 04:39 PM #1
- 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?
-
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
-
the syntax for malloc is
ptr = (typecasting)malloc(sizeof(datatype));
if u have any doubt please dont hesitate to ask
-
Sponsored Ads

Reply With Quote





