Please tell me if this program runs or notCode:main() { printf("%d",i); sum(); printf("%d",i); } static int i; sum(void); { ++i; }
If error occurs, what should be the error and the reason ?
thanks
Please tell me if this program runs or notCode:main() { printf("%d",i); sum(); printf("%d",i); } static int i; sum(void); { ++i; }
If error occurs, what should be the error and the reason ?
thanks
The program compiles and runs without any error.
Are you sure you can trust me? Read the homework policy and use your compiler to find out if I told you the truth.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
If this is all code there is, then it may compile, but should not necessarily do so.
You suffer firstly from "default int". All functions should return something. Not nothing.
Secondly, since the definition of sum appears below main, it should have a prototype (every function should have one, really).
Thirdly, there is a stray ; after the function definition of sum.
It certainly won't since i was not declared before the first two points where it is used.Originally Posted by Elysia
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Also "i" isn't declared and there is no value assigned to it. Plus even if you do all that the program probably won't do what you liked it to do...
edit: damn I'm slow
Including a certain header file would help too.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
> Please debug this program\b\b\b\b\b\b\b\b\b\b\bunblock my toilet.
Er, no.
Get a compiler, and use it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.