Thread: char[] vs char*
View Single Post
Old Apr 15th, 2008, 1:18 PM   #11
Ka0s
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0 Ka0s is on a distinguished road
Re: char[] vs char*

Well... you are saying that it's not possible to change a string literal declared has a pointer but i've compiled this code and it worked:

#include <stdio.h>

int main() {
	char *a = "hello";
	printf("%s\n", a);
	*a = 'a';
	printf("%s\n", a);

	return 0;
}

When i run the program it shows "hello" followed by "aello".
Can you tell me why can i modify the string pointed by "char *a"?
Ka0s is offline   Reply With Quote