Question 16.6

Why does this code:

char *p = "hello, world!";
p[0] = 'H';
crash?


String literals are not necessarily modifiable, except (in effect) when they are used as array initializers. Try

	char a[] = "hello, world!";
See also question 1.32.

References: ANSI Sec. 3.1.4
ISO Sec. 6.1.4
H&S Sec. 2.7.4 pp. 31-2


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback