-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
#include<stdio.h>
#include<conio.h>
conio.h is not a standard header. It's contents could be anything, and could
affect your program in ways we cannot determine
#include<string.h>
main()
main() takes either two arguments or none, and returns an int
you should use one of the two legal variants here, likely
int main(void)
a is declared as a pointer to an array of 4 char.
a can be altered
the array of 4 char cannot be altered
clrscr() is not a standard function. It's actions and side-effects could do
anything, and will affect your program in ways we cannot determine.
At least, undefined behaviour, because *a is only 4 char long, and the
side-effect (and function) of strcpy() would be to overwrite that space with a
6 char long value. 6 chars don't fit into a 4 char space.
The more knowledgable ones around here will tell you whether this is "illegal
behaviour" (because of the side-effect of strcpy(), which would be to attempt
to overwrite a char constant) or just "undefined behaviour".
Legal. You are not replacing the constant char array, you are replacing the
variable pointer.
IIUC, this should be illegal.
main() returns an int. return one here.
(Unless, your compiler is C99 compliant, in which case, the return value is
optional and defaults to a pre-determined value).
}
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??
The compiler is non-compliant?
The compiler is broken?
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (
http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFCc5PDagVFX4UWr64RAs8TAJ4p+ZyxVWzyLHSghtGc9yAdO9altQCgkxAZ
TDeV/fVJ3HZ6ZPh/iGDjvb8=
=jTH7
-----END PGP SIGNATURE-----