Re: output unexpected



Vaibhav87@xxxxxxxxx said:

i write
void main()
{
int j;
j - = 0;
printf("%d",y);
}
& i got the answer as 842.

I got several diagnostic messages from my compiler, which refused to produce
an executable program:

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c:2: warning: function declaration isn't a prototype
foo.c:2: warning: return type of `main' is not `int'
foo.c: In function `main':
foo.c:4: parse error before `='
foo.c:5: warning: implicit declaration of function `printf'
foo.c:5: `y' undeclared (first use in this function)
foo.c:5: (Each undeclared identifier is reported only once
foo.c:5: for each function it appears in.)
make: *** [foo.o] Error 1

i tried it on various computers but the
answer is same.

I'm surprised you got any compiler to produce an executable program.

pls help me
how is this answer is?

What answer were you expecting it to produce, and why?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: Problem compiling
    ... cgi.c:148: warning: function declaration isn't a prototype ... but argument 3 has type 'int' ...
    (Debian-User)
  • Re: Compile Time Error ... arghh
    ... foo.c:12: warning: function declaration isn't a prototype ... foo.c:13: warning: implicit declaration of function `malloc' ... int ccarray_destroy; ... char *dupstr; ...
    (comp.lang.c)
  • Re: [OT:] FTP clients
    ... dspfile.h: In member function `int DSPFile::vec2disk': ... dspfile.h:124:7: warning: no newline at end of file ... dspfile.h:72: error: (Each undeclared identifier is reported only once for each ...
    (sci.electronics.design)
  • Re: Abnormal program termination
    ... foo.c:4: warning: function declaration isn't a prototype ... Your version is legal under C90 rules, but int mainis more explicit ... float ave(), average; ...
    (comp.lang.c)
  • Re: WinPCap Problems
    ... C2065: 'captime': undeclared identifier ... warning C4024: 'strftime': different types for formal and actual ... indirection from 'int ' ...
    (microsoft.public.win32.programmer.networks)