what codes do you use in order to repeat the whole process of a program?
(P.s: i think its "for loop" or "do while" but i dont know where to place it since its in parameter passing by reference..)
help...
I am not real keen on beginners routinely using infinite loops because it is perceived to be easier. It can lead to messy code if not used in the right situation. It is needed when the end condition is complicated and or dependent on other variables.
If I do need to do an infinite loop, I use for(;;) because it will work with any language that has a for loop in this format.
Instead it would be better IMO to use a while or for loop with an appropriate end condition.
There are situations where infinite loops are warranted, but not IMO because one is too lazy to come with an end condition.
@ Rechard3
It is int main() not void main() according to the standard. There are a lot of people in India who use really ancient Borland Turbo C++ 3.0, who tend to do this. It won't compile on a modern compiler.
Group of Eight is right about using void when there are no arguments / parameters for a function. AFAIK it has never been a requirement in C++.
It is int main() not void main() according to the standard
actually this is what the standard specified:
Basic Concepts
3.6 Start and termination
3.6.1 Main function
...
2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return
type of type int, but otherwise its type is implementation-defined.
...
VC++ 98, VS 2010 support both return types (int, void).
if your compiler doesn't support both ways, then probably you should consider getting a better one.
you shouldnt void main anymore. "upgrading" to a compiler that supports it isnt a good idea. we are in c++11 now and shouldnt go that far to support void
VC++ 98, VS 2010 support both return types (int, void).
if your compiler doesn't support both ways, then probably you should consider getting a better one.
Or you should consider actually doing it the correct way and then you wouldn't have to worry about if your compiler supports it or not... Generally in C++ you should avoid non standard things in your programs.
And you are incorrect Rechard void main() is non standard.
Consider when you work on a large project with multiple members on the team (Like open source software) generally you stay away from things that only work on a certain compiler (Like void main()) because is causing unneeded problems.
Rechard3 wrote:
actually this is what the standard specified:
Basic Concepts
3.6 Start and termination
3.6.1 Main function
...
2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return
type of type int, but otherwise its type is implementation-defined.
...
You kind of skipped the whole part of it saying "It shall have a return type of type int" ;p
It shall have a return type of type int, but otherwise its type is implementation-defined.
this means int main(), int main(int argc, char* argv[]) and other implementation-defined forms, such as the very common int main(int argc, char* argv[], char* envp[]) are allowed. The return type of void was never allowed in C++: void main() is prohibited by the quoted sentence.
What actually happens is that the Microsoft C runtime library (CRT) provides an implementation of main that calls either WinMain or wWinMain.
The CRT does some additional work inside main. For example, any static initializers are called before wWinMain. Although you can tell the linker to use a different entry-point function
one example i can think of is lets say you use system and you only want to continue if the program executed correctly. you would test it with the return value of main