On Apr 9, 7:40 am, significantBit <jfonte...@gmail.comwrote:
n00b here. Just started learning C a couple of days ago. I'm using
xcode alternatively with emacs.
My question is in regards to the main function.
Everytime I create a project (standard command utility) with xcode, my
main function starts out looking like this:
int main(int argc, const char * argv[])
What's all this in the parenthesis? Why use this rather than just
main() ???
If you want to be able to process arguments from the command line, you
need these two parameters. argc contains the number of arguments on
the command line (including the program name), and argv is the list of
actual arguments (represented as character strings). For example, if
you create a project foo and invoke it as follows:
$ foo bar bletch
argc will have the value 3 (there are three elements on the command
line), and argv will contain the following:
argv[0] = "foo"
argv[1] = "bar"
argv[2] = "bletch"
If you don't intend to read any arguments from the command line, you
can type main() as
int main(void)
That signature explicitly says that main() takes no arguments.