7 Replies - 331 Views - Last Post: 14 January 2013 - 08:34 PM Rate Topic: -----

#1 digitalweb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-September 12

Question about command line arguments.

Posted 14 January 2013 - 12:25 PM

i have a question that why do we write argc and *argv[] as
arguments to main when we don't need commandline arguments???

This post has been edited by modi123_1: 14 January 2013 - 12:28 PM
Reason for edit:: fixed botched quote tags

Is This A Good Question/Topic? 0
  • +

Replies To: Question about command line arguments.

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4076
  • View blog
  • Posts: 12,589
  • Joined: 25-December 09

Re: Question about command line arguments.

Posted 14 January 2013 - 12:36 PM

Please don't ask help questions in the Chalenges forum, ask the question in the C/C++ forum. Topic split.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 780
  • View blog
  • Posts: 2,312
  • Joined: 20-March 10

Re: Question about command line arguments.

Posted 14 January 2013 - 12:47 PM

View Postdigitalweb, on 14 January 2013 - 07:25 PM, said:

i have a question that why do we write argc and *argv[] as
arguments to main when we don't need commandline arguments???


Hi,

If you dont need arguments you can write main as

int main()
{


.......

return 0;
}



However sometimes you do need arguments..

Best Wishes


Snoopy.

This post has been edited by snoopy11: 14 January 2013 - 12:49 PM

Was This Post Helpful? 2
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Question about command line arguments.

Posted 14 January 2013 - 12:58 PM

Quote

why do we write argc and *argv[] as
arguments to main when we don't need commandline arguments???


There's no reason at all, I guess you should ask the programmer why they did it.
Was This Post Helpful? 2
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,345
  • Joined: 08-August 08

Re: Question about command line arguments.

Posted 14 January 2013 - 03:52 PM

Some IDEs will start you off with a template. Mine does this:
#include <iostream>

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

	// insert code here...
	std::cout << "Hello, World!\n";
    return 0;
}


I frequently forget to remove the arguments for main().
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 780
  • View blog
  • Posts: 2,312
  • Joined: 20-March 10

Re: Question about command line arguments.

Posted 14 January 2013 - 04:56 PM

400 points woohoo...

danke sepp2k

Es bedeutet viel für mich !

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#7 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1074
  • View blog
  • Posts: 4,533
  • Joined: 09-June 09

Re: Question about command line arguments.

Posted 14 January 2013 - 08:29 PM

Quote

i have a question that why do we write argc and *argv[] as
arguments to main when we don't need commandline arguments???


The question should be phrased, "why do you write command line arguments if you don't need them" ? Most programs that run in some sort of shell, take some sort of command line arguments.

For example, look at theses unix commands ran out of a shell

cd some_directory
ls -l
diff -c file1.out file2.out

Everything specified after the initial command is considered a command-line arguments (The command itself is also passed as a argument as well). Some compilers allow for a 3rd parameter which contains all environment information.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5327
  • View blog
  • Posts: 27,243
  • Joined: 10-May 07

Re: Question about command line arguments.

Posted 14 January 2013 - 08:34 PM

Seeing that you are from India : I would take "We" to mean Indian developers. & the reason for the un-needed arguments can be answered with another question : Why do you learn on a dead compiler such as Turbo C++?

There are not logical answers to these questions, but as best as we can gather, it just is the way it is. Either the schools don't want the students to graduate as useful, or there is some ego tug-of-war where it is not ethical for the students to ask questions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1