why o/p like this ?

G

Gordon Burditt

void main()
{
int val=2;
val = - --val- val-- - --val;
printf("%d",val);
}
o/p-> -1

This program ought to invoke the death penalty, and that's just
for the void main() part.

There is no wrong output from this program. It invokes the wrath
of undefined behavior. Even "supercalifragilisticexpealidocious"
or a live grenade without the pin is valid output..

Gordon L. Burditt
 
K

Keith Thompson

void main()
{
int val=2;
val = - --val- val-- - --val;
printf("%d",val);
}
o/p-> -1

You're invoking undefined behavior; the result could be anything.

See the C FAQ <http://www.eskimo.com/~scs/C-faq/faq.html>, section 3.
You should serioulsy consider reading the entire FAQ while you're at
it. The HTML version hasn't been updated lately; the compressed plain
text version at <ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.gz> is the
most current one available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top