Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,460 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,111 people online right now. Registration is fast and FREE... Join Now!




main

 
Reply to this topicStart new topic

main

c--
4 Feb, 2008 - 09:18 PM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 27

what does this means...?

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

Why do some people add those parameters there?
I know you are declaring an integer argc, and an array (args[]) pointer of type char.

But where can I use it??


User is offlineProfile CardPM
+Quote Post

WXY
RE: Main
4 Feb, 2008 - 09:52 PM
Post #2

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
They are used for command line parameters to your program. Let's say your program is named "foo.exe". Those two paramiters enables you to receive options via command line options eg: "foo.exe -someOption someValue"
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Main
4 Feb, 2008 - 10:16 PM
Post #3

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
int argc is a number containing the number of elements in the array char* args[].

It's short for "argument count" and "arguments". In this case, as WXY stated, the arguments are the command line arguments.

A parameter and an argument in a function declaration are the same thing.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Main
5 Feb, 2008 - 10:36 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,026



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Not many people know this, but main() also accepts a third parameter which contains all the environment variables.

Check out this example I wrote:
CODE
#include <iostream>
#include <cctype>

using namespace std;

int main(int argc,char** argv,char **env)
{
    int i=0;
    
    while(*(env[i++]))
    {
        cout<<"COUNT = "<<i<<" = "<<env[i]<<endl<<endl;
    }

  

  return 0;
}

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Main
5 Feb, 2008 - 10:44 AM
Post #5

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,116



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(c-- @ 4 Feb, 2008 - 10:18 PM) *

what does this means...?

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

Why do some people add those parameters there?
I know you are declaring an integer argc, and an array (args[]) pointer of type char.

But where can I use it??

http://www.dreamincode.net/forums/showtopic30387.htm
User is online!Profile CardPM
+Quote Post

c--
RE: Main
5 Feb, 2008 - 08:25 PM
Post #6

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 27

Thanks for the replies. smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 01:57PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month