List of all available Websheets
Viewing cpp/arrays/examples/arraybad by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | An example of unpredictable behaviour. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; int main() { \[ \show: int arr[3]; // declare an array int thirteen = 13; // never changes cout << "Badness: reading out of bounds!" << endl; cout << arr[3] << endl; cout << arr[-1] << endl; cout << "Worse: writing out of bounds!" << endl; arr[-1] = 34; cout << "thirteen is now: " << thirteen << endl; cout << "Writing out of bounds. C++ prevents nothing :(" << endl; arr[3] = 103; cout << arr[3] << endl; cout << "Let's crash the program!" << endl; arr[340912983] = 78676; cout << "This line won't execute." << endl; return 0; ]\ } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {} ] |
Solution visibility | |
Is example? i.e., just a demo | |
Add compiler flag(s) json list of flags e.g. ["-Wno-unused-variable"] | ["-Wno-array-bounds"] |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.