Sunday 22 July 2012

Bound Checking of an Array in C

Bound Checking of an Array in C

In C there is no check to see whether the bounds of an array exceeds the size of the array.
We know that array elements are placed in contiguous memory locations.
If data is entered having a subscript exceeding array size then it is placed in memory outside the array.
This may lead to unpredictable results.
There are no error or warning messages to warn that we are exceeding the array size.
We can use the following program to see what happens when array bounds exceed the array size:

/* Program for understanding the bounds of an array*/

#include<stdio.h>
#include<conio.h>

void main()
{
int i,num[2];

//Assigning values to array elements beyond its size
for (i=0;i<10;i++)
 {
 num[i]=i; 
} //Printing the value assigned to the array
 for(i=0;i<10;i++)
printf("num[%d]= %d" ,i,num[i]);
 }
 }
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: