Re: a few doubts!
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Apr 2005 16:10:48 +0100
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.
.
- Follow-Ups:
- Re: a few doubts!
- From: Emmanuel Delahaye
- Re: a few doubts!
- References:
- a few doubts!
- From: maadhuu
- a few doubts!
- Prev by Date: Re: a few doubts!
- Next by Date: typedef struct
- Previous by thread: Re: a few doubts!
- Next by thread: Re: a few doubts!
- Index(es):