Discussion: Whoa! Hold on There
Execute the code to understand the output and gain insights into buffer overflow.
We'll cover the following...
Run the code
Now, it's time to execute the code and observe the output.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int array[5]; int x; srand( (unsigned)time(NULL) ); for( x=0; x<12; x++ ) { array[x] = rand() % 100; printf(" %d", array[x]); } putchar('\n'); return(0); }
C code for the given puzzle
Understanding the output
The code fetches random numbers, packing them into an array. Due to overflow, however, a segmentation fault or similar error is generated. Different compilers create programs that may display erroneous data, such as very large values. Some ...