7 Replies - 34844 Views - Last Post: 25 August 2008 - 02:43 PM Rate Topic: -----

#1 zerogee   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 20-August 08

about int main (int argc, char **argv)

Post icon  Posted 22 August 2008 - 09:16 AM

hi guys,

i see this alot, but i've never used it in a program, and i dont know whats it used for, so if someone can help me i'll be thankful :)
Is This A Good Question/Topic? 0
  • +

Replies To: about int main (int argc, char **argv)

#2 Akelo   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 98
  • Joined: 12-December 07

Re: about int main (int argc, char **argv)

Posted 22 August 2008 - 09:22 AM

View Postzerogee, on 22 Aug, 2008 - 09:16 AM, said:

hi guys,

i see this alot, but i've never used it in a program, and i dont know whats it used for, so if someone can help me i'll be thankful :)


The main() is in many ways, nothing more than a glorified function, and those are variables that can be passed from the command line into the actual program.
Was This Post Helpful? 0
  • +
  • -

#7 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: about int main (int argc, char **argv)

Posted 22 August 2008 - 11:07 AM

A little more detail to shed a bit more light on the subject:

Basically, they are parameters, which are passed to the program from another program~ most commonly, the system shell (cmd if you are on Windows)

main()
The entry point into any console application. As you delve into graphics development, you'll notice that it isn't always this. However, to keep things simple, let's just stick with main on its own. :)

int argc;
Stands for argument count. In other words, how many things are being passed into the program.

char **argv; or char *argv[];
Both do the exact same thing. Short for argument vector, or in other words, this is a multidimensional array that will store all arguments being passed to the function.

For a tutorial, click here.

Hope this helps :)
Was This Post Helpful? 4

#8 wartech   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 203
  • Joined: 16-October 06

Re: about int main (int argc, char **argv)

Posted 25 August 2008 - 09:44 AM

Thanks for the info gabehabe. I had been wondering about this myself.
Was This Post Helpful? 0
  • +
  • -

#9 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: about int main (int argc, char **argv)

Posted 25 August 2008 - 01:14 PM

Wow, I think it was worth posting about that. I've been thanked twice for it today alone! :)
Was This Post Helpful? 0
  • +
  • -

#10 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: about int main (int argc, char **argv)

Posted 25 August 2008 - 01:26 PM

its either a pointer to a pointer of arguments or a pointer to an array of them, not necessarily multidimensional
Was This Post Helpful? 0
  • +
  • -

#11 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: about int main (int argc, char **argv)

Posted 25 August 2008 - 02:33 PM

But their behaviour simulates that of a multidimensional array, no matter how it is written. Correct?
Was This Post Helpful? 0
  • +
  • -

#12 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: about int main (int argc, char **argv)

Posted 25 August 2008 - 02:43 PM

not explicitly, otherwise it would be written as [][], however you can allocate any memory you want, so yes it could be multidimensional

especially since an array declared with a [] is simply a pointer to the first object (implicit conversion)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1