wrong output

V

Vaibhav87

i write
void main()
{
int j;
j - = 0;
printf("%d",y);
}
& i got the answer as 842. i tried it on various computers but the
answer is same. pls help me
how is this answer is?
 
O

osmium

i write
void main()
{
int j;
j - = 0;

I wouldn't expect that to compile with a space between the two operators.

It makes no sense to do arithmetic on an unknown value.

printf("%d",y);

Where is y declared?

Are you sure you're using cut and paste?
 
C

CBFalconer

i write
void main() *** ERROR - main return int.
{
int j;
j - = 0; *** ERROR unknown syntax
printf("%d",y); *** ERROR y undefined
}
*** ERROR failure to return exit status.
& i got the answer as 842. i tried it on various computers but the
answer is same. pls help me
how is this answer is?

What's wrong with the answer? Anything is legal when the behaviour
is undefined.
 
K

Keith Thompson

i write
void main()
{
int j;
j - = 0;
printf("%d",y);
}
& i got the answer as 842. i tried it on various computers but the
answer is same. pls help me
how is this answer is?

That code doesn't even compile, and it's almost certainly *not* the
code that you actually tried. Are you expecting us to guess what your
real program looks like?

Copy and paste the *exact* code that you actually compiled.

main() returns int, not void. Change "void main()" to "int main(void)".

"j - = 0;" is a syntax error. I won't try to guess what you actually
meant.

You try to print the value of y, but you never declared it.

Since you use printf() you need to add "#include <stdio.h>" to the top
of your program.

Since main returns an int, you should return an int: add "return 0;"
after the printf call. (This isn't always required, but it's always a
good idea.)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top