PROGRAMMING IN C LANGUAGE ONLY Write a program that defines

PROGRAMMING IN C LANGUAGE ONLY

Write a program that defines an array of type integer. Print out the array elements and go deliberately *beyond* the end of the array, i.e. read/output array elements with indexes that are not accomodated by the array definition. Now extend your program to continuously write beyond the end of the array. Output the indeces of the elements that you wrote and check, how many elements you can get away with writing at illegimate locations. What are your conclusions of what you see?

Solution

#include <stdio.h>
#include <stdlib.h>

int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10},i;
for(i=0;i<20;i++)
printf(\"%d\ \",a[i]);
i=10;
while(i<15)
{
printf(\"Enter an Element %d\ \",i);
scanf(\"%d\",&a[i]);
i++;
}
for(i=10;i<20;i++)
{
printf(\"%d\ \",a[i]);
}
return 0;
}

1) When we are trying to print the values beyond the size we can see that garbage values will be printed.

2) We cannot try to write the values beyond the capacity of the array if so then that will be an infinite loop

PROGRAMMING IN C LANGUAGE ONLY Write a program that defines an array of type integer. Print out the array elements and go deliberately *beyond* the end of the a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site