First, a caveat. I'm a bit of a begginner in Arduino and AVR MCUs, so there is probably something innacurate in what I'll say. If that's the case, feel free to just edit, criticize or downvote. In any case, I wanted to go into a little more detail than others have gone with their ansewers.
So, let's see a few examples of what can go wrong.
Uninitialized variables
int status; pinMode(13, OUTPUT); digitalWrite(13, status); This problem is pretty harmless, but nobody knows whether the LED will light up or not. The value of variable status will be whatever happens to be the value that memory position was initialized with. But it's not defined in your program.
Memory overflow
int array[10]; int v = array[100]; array[-100] = 10; The first problem here is that you don't know what will be assigned to v, but worse is that you don't know what you messed up with the assignment to position -100 of array. The good news is that you only messed up with RAM and not with the EEPROM, thus your program is safe.
Jump to an illegal instruction
void doSomething( void ) { for (int i = 0; i < 1000; i++); } void setup () { void (*funcPtr)( void ); funcPtr = &doSomething; funcPtr(); // calls doSomething(); funcPtr = NULL; funcPtr(); // undefined behavior } The first call to funcPtr() will actually be a call to doSomething(). The second one will lead to undefined behavior. It will probably continue execution from memory address 0. What's there? The bootloader begins there? I don't know, need to read the compiler fine print. But certainly it is not the intended behavior.
Other bad things that may happen
Well, you can run out of RAM, for example. What else. In any case, I think your program will keep running, probably not the way you intended it to.
Summary
In computer systems, problems like these are usually dealt with at various levels:
- By the compiler
- By the programming language runtime (as in Java for example).
- By the operating system or the processor (if your memory access a position outside the boundaries of the address space reserved to your program, the OS or the processor may have safety mechanisms to prevent that)
Arduinos only have only limited protection of the compiler, and probably nothing else. The good news is that they aren't multi-tasked, so the only program being affected is yours. In any case, any of those bugs will lead to erratic behavior.