13_Command-Line Arguments

It is possible to pass some values from the command line to your Objective-C programs when they are executed. 

These values are called command line arguments

The command line arguments are handled using main() function arguments where

  • argc refers to the number of arguments passed,
  • and argv[] is a pointer array, which points to each argument passed to the program.

Example

It should be noted that argv[0] holds the name of the program itself and argv[1] is a pointer to the first command-line argument supplied and *argv[n] is the last argument.

If no arguments are supplied, argc will be one, otherwise if you pass one argument, then argc is set at 2.

Example 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: