i need a C program that will do this if the picture too smal

i need a C program that will do this. if the picture too small open it in a new tap

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\"

int main(void) {
int arr[2];
   int i;
   for(i=0;i<6;i++){
       scanf(\"%d\",&arr[i]);
   }
   printf(\"Address Numbers\ \");
   for(i=0;i<6;i++){
       printf(\"%p \",&arr[i]);
   }
   printf(\"Numbers\ \");
for(i=0;i<6;i++){
   printf(\"%d \",arr[i]);
}
return 0;
}

/*
sample outputs
1 2 3 4 5 6
Address Numbers
0x7ffd80a3bf10 0x7ffd80a3bf14 0x7ffd80a3bf18 0x7ffd80a3bf1c 0x7ffd80a3bf20 0x7ffd80a3bf24
Numbers
1 2 3 3 4195536 5

6 5 4 3 2 1
Address Numbers
0x7ffc67e2df80 0x7ffc67e2df84 0x7ffc67e2df88 0x7ffc67e2df8c 0x7ffc67e2df90 0x7ffc67e2df94
Numbers
6 5 4 3 2 1

10 11 12 13 14 15
Address Numbers
0x7ffc8a1ebe50 0x7ffc8a1ebe54 0x7ffc8a1ebe58 0x7ffc8a1ebe5c 0x7ffc8a1ebe60 0x7ffc8a1ebe64
Numbers
10 11 12 3 4195536 0

*/

Arrays in c get contiguous memory locations. On adding elements beyond the array size,the elements gets stored in the location contiguous to the array replacing any information contained in that location.

If the program allocations that memory to any other objects the elements contiguous to the location will be lost.

There will be segmentation fault error if program tries to write to a location which has some useful system information.

i need a C program that will do this. if the picture too small open it in a new tap Write a program that defines an array of type integer Print out the array el

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site