Difference between "void main()" and "int _tmain(int argc, _TCHAR* argv[])"?

Hello. I am learning C++ and I am following a series of educational videos + some books. All these
books declare the main function as

void main()

However, when I downloaded and installed VC++ Express 2008 the default main declaration is

int _tmain(int argc, _TCHAR* argv[])

The programs run fine as well, but I really don't understand what's the difference, and it really bugs me the fact that I am using something I don't really understand. Adding to the confusion there's the fact that the videos I am
using use Microsoft Visual C++ as well (although I can tell it is not the 2008 version, probably an older one.)

So, basically what I would really know is:

1. The difference between the two declarations
2. Which one of the two should I consider "standard"
3. If there's really no standard to speak of,  but it is something strictly linked to my actual development environment, which in this case is VC++ 2008 Express.

Thank you. :)

(By the way, just in case it wasn't already clear, I'm a beginner as a beginner could be.)
Who is Participating?
sunnycoderConnect With a Mentor Commented:
1. The difference between the two declarations
main () is the function from which execution of your code starts - the user code entry point
void main() means main function returns nothing - void
() after main indicate that the function has empty argument list - does not take any argument.

_tmain() is microsoft specific entry point for user code that resolves to main. This would not work in other programming environments.
It returns an int and takes 2 arguments - int argc the number of arguments, _TCHAR * argv[] an array of strings -
he actual command line arguments

2. Which one of the two should I consider "standard"
Neither ... standard says
int main (int argc, char * argv[])

3. If there's really no standard to speak of,  but it is something strictly linked to my actual development environment, which in this case is VC++ 2008 Express.
I guess I answered that above
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
void main()

is the default implementation for an ascii/ansi application, it could be also:

int main(int argc, char *argv[])

if you need to read the command-line arguments. The following implementation:

int _tmain(int argc, _TCHAR* argv[])

is the default implementation for Unicode application, but can be used for ascii/ansi too. If you won't use the command-line arguments, just ignore them.
torimarConnect With a Mentor Commented:
_TCHAR* argv[] is a pointer to the argument that the programme is started with, like:
"myexe.exe thisfile"  or "myexe.exe -a -b"

argc contains the number of arguments (argv) that the exe was started with.

'int' _tmain instead of 'void' will most likely refer to the fact that VC++ executables always return an exit code on ending in order to communicate to the OS whether they were correctly ended or aborted etc

As you have seen, your exercises work with this template just as well. It's just a more difficult or exact way of putting it.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Too slow :) ... sorry for the repeated points
Yes I agree with sunnycoder.

The only standard in C++ is
int main()
int main(int argc, char* argv[]) (if you want to pass in parameters through command line)

This (int _tmain(int argc, _TCHAR* argv[])) is Windows specific, and is specific to the Visual Studio environment only.
broocryptAuthor Commented:
Thank you everyone. Super clear now. It seemed unfair to give all the points to just one expert, since almost everyone added something to others' answers and viceversa. I divided them based on usefulness and effort. Hope you guys don't mind. Don't worry - as a beginner I will post a LOT more questions to gain points with. :))
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.