Beginner question. Why will this code crash?

If i remove line 7, the code will run. If I don't remove it, it'll run. My question is why would this happen.

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
int main() 
{
	char *p = "Hello":
	cout < p;
	p[0] = 'z';

	return 0;
} 
> Why will this code crash?

With a conforming compiler, with or without line 7, this code will not compile.
http://coliru.stacked-crooked.com/a/851de79518c97cd2

The string literal "Hello" is an object of type 'array of 6 const char' and static storage duration. (The characters in the the array are not modifiable.)
Topic archived. No new replies allowed.