| View previous topic :: View next topic |
| Author |
Message |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Sat Sep 22, 2007 7:25 am Post subject: c++ int main() / void main() ? |
|
|
well i reading a book (my 2 friends read books too)
and in all the books they always say use "int main()" but my programing friend say it is wrong i should use "void main()" oO
why does the book say i should use int always and he say void and whats the best ....
or dosent it effect my programs anyway ?
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Sat Sep 22, 2007 7:34 am Post subject: |
|
|
Well it's good practise to use int main(), even if you don't want to return a value. void means no return value and int means return value. The reason is that, if you use int, and then return 0, or 1, it will know if there is an error or not, so it's just good practise.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Sep 22, 2007 7:34 am Post subject: |
|
|
It works either way. Theres more then just those as well.
int main() expects a return value. While void main() doesn't.
Then you can also have stuff like:
int _tmain(int argc, _TCHAR* argv[])
Which gives you access to things easily such as the current folder path via the argv array and various other things. (They are used for command line functions and such.)
Edit:: Bah, --Pillboi-- beat me to the post lol. And yea, like he/she said, using a return value for everything is good practice.
|
|
| Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Sat Sep 22, 2007 10:09 am Post subject: |
|
|
some compilers will give error if you use void
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Sat Sep 22, 2007 11:00 am Post subject: |
|
|
| you should not use void main() because the shell needs to know whether you succeeded or failed
|
|
| Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
Posted: Sat Sep 22, 2007 11:10 am Post subject: |
|
|
| appalsap wrote: | | you should not use void main() because the shell needs to know whether you succeeded or failed |
Exactly what appalsap said;
More reading on the matter;
http://www.eskimo.com/~scs/readings/voidmain.960823.html
_________________
0x7A 0x61 0x72 0x74
TEAM RESURRECTiON |
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Sat Sep 22, 2007 12:12 pm Post subject: |
|
|
okay thanks =D
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Sep 22, 2007 1:11 pm Post subject: |
|
|
void main(void)
{
//Block
}
This is a sample in C
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Sep 22, 2007 1:38 pm Post subject: |
|
|
| Kaspersky wrote: | void main(void)
{
//Block
}
This is a sample in C |
edit: nvm
_________________
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sun Sep 23, 2007 7:54 pm Post subject: |
|
|
| Kaspersky wrote: | int main(void)
{
//Block
return 0;
}
This is an improved sample in C |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Sep 23, 2007 7:57 pm Post subject: |
|
|
lol
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Sep 24, 2007 5:12 am Post subject: |
|
|
| Flyte wrote: | | Kaspersky wrote: | int main(void)
{
//Block
return 0;
}
This is an improved sample in C |
|
I'm still a begginer in C, shit!.
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Mon Sep 24, 2007 5:23 am Post subject: |
|
|
why do all write in C lol thats older then my gfs brother oO like +31 years ago ...
c++ is so much better
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Mon Sep 24, 2007 5:27 am Post subject: |
|
|
| ups2000ups wrote: | why do all write in C lol thats older then my gfs brother oO like +31 years ago ...
c++ is so much better |
c/c++ entry points are same
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Sep 24, 2007 5:31 am Post subject: |
|
|
| ups2000ups wrote: | why do all write in C lol thats older then my gfs brother oO like +31 years ago ...
c++ is so much better |
You MUST! learn C before anything else -_-" !
It's like learning math without knowing 2*2 or 1+1 -_-
@ Robotex
Wrong.
They have diffrent syntax, for example:
C is printf(" ")
C++ is cout << " " (not 100% sure)
|
|
| Back to top |
|
 |
|