Could someone explain this?

This topic is 1399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Is there like any different between these two main functions? I was just exploring the internet looking at code and notice this small difference.

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

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



Share on other sites
And this:
int main()


Share on other sites

Nah I know about declaring the type of function.

Share on other sites

And this:

int main()


Are you trolling now? Because, i can't tell if you are or if this is a question.

Share on other sites

COOL! That solve one of my problem even if breaks the rules of pointers. You guys didn't notice args or does that not matter as well?

Share on other sites

I just thought the name would have more important in a main function and it used a lot. Thanks for clearing this up

Share on other sites

And this:

int main()


Are you trolling now? Because, i can't tell if you are or if this is a question.
It's a real question. I've seen those things before within the main() and didn't know what they did.

Share on other sites

And this:

int main()


Are you trolling now? Because, i can't tell if you are or if this is a question.

This is the guy who thinks he is going to create a more realistic GTA V replicate. The same guy who had half a page of quotes for a signature. The same guy who has been learning C++ for the last 4 months and doesn't know what a command line argument is. The same guy who has been part of the community for for 5 months, posted almost 500 posts and has a reputation of -367.

That Guy.

I apologize to the original poster whos topic has been hi-jacked.

Share on other sites

int main() just means that you don't care about command line arguments.
You can either use:
int main() -- and get no arguments.

Thanks.

My point is self-explainatory, need I say more? Your attention to detail is appalling my username is Kirkkaf13 (two k's one f), that is what is called a bug, I am sure you are familiar with them.

The original question has been answered, I think this thread should be closed before Nathan2222 posts and receives more down votes. Again, I would like to apologize for my actions but this is infuriating.

For the people reading this thinking I am being unreasonable or some sort of jerk, please read through Nathan2222 previous posts and thread hi-jacks.

Edited by Kirkkaf13

Share on other sites

I just thought the name would have more important in a main function and it used a lot.

They're important, yes. Names are vital to communicate intent to other programmers. Hence, dyou certainly shouldn't take Hodgman's suggestion of [b]Sally[/b] too seriously!

But funnily enough C++ does not require that the names match between declarations and definitions.

void example(int one, int two);

int main()
{
example(42, 13);
}

void example(int a, int b)
{
std::cout << "A: " << a << ", B:" << b << std::endl;
}


In fact, you don't need to provide names when declaring a function, and if you don't wish to use a parameter you don't need to give it a name in a definition:

void example(int, int);

int main()
{
example(42, 13);
}

void example(int a, int)
{
std::cout << "A: " << a << ", but we don\'t care about B..." << std::endl;
}


It is typical for them to be present and to match, again to help provide clarity.

Thus, to the code that "calls" main, i.e. the [i]runtime[/i], it doesn't matter what the parameters names are or if they even have names.

Share on other sites

Related to function/parameter naming, [b]main[/b] has to be called main. You can't rename that.

(Well, for console stuff, at least. Win32 has different naming requirements, etc.)

Share on other sites

For posterity, it's probably worth also pointing out that since the start of an array is kinda the same as a pointer, this is also valid:

int main (int argc, char** argv)

Share on other sites

*edited out*

Somehow I missed reading over half the posts in this thread.  No new information here.

Share on other sites

This topic is 1399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.