Re: a few doubts!



maadhuu wrote:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char * a= "bcd";
clrscr();
strcpy(a,"hello");
a = "fgh"; a[0] = 't';
printf("%s",a);
}


now, in TC there is absolutely no error .....i thought it
should........coz' when i declare a as a char * and assign it to some
string then it should be a constant and cannot do things like a[0] = '4'
and stuff........infact the entire thing here works properly....so why
should it work properly??

It worked properly because it was neither an important demo with a large sale hanging off it nor you showing it to your boss.


The standard says you are not allowed to write to a string literal, it does not say it will generate an error or crash if you do.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.