-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
code said:
Hi all.
Can you tell me the reason .
1)why compile is not giving error ?
The compiler is not reporting an error because you do not have an error.
2)if not error then the value of x should be 10 but it is printing junk
value.
You are wrong. In the case you are concerned about, x is not
initialized, so junk is one of the possible outputs.
The code is :-
include <stdio.h>
int x = 10;
static int y;
OK, you've defined two global variables: x and y
*Unless otherwise overridden* these two variables will be available to
every function in your program.
Here, you override the global variable x and define a local variable x
You assign this local variable x the value given to the /local variable/ x.
What you've done is roughly equivalent to:
int x; /* define local variable x (/
x = x; /* initialize local variable x from local variable x */
Since you didn't initialize x with anything, the initializer is "junk"
(as you put it), and later uses of this value of x will reproduce "junk".
Here, you override the global variable y and define a local variable y
Of course, you didn't provide initial values for either x or y, so this
printf will print "junk" for each.
return 0;
}
i'm using microsoft visual studio compiler ...
I'm sorry. I hope you soon can afford a real C compiler :-(
i hope you guys get back to me with reason....
this help me lot....
- --
Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org
iD8DBQFETMPsagVFX4UWr64RAuQ+AKDaNTIFKdFuVFUauO6YzVDAS8bAiwCaApEj
t800VEjK3SZd/OReyf3ggok=
=vs6N
-----END PGP SIGNATURE-----