
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What is a command line argument in C language?
An executable instruction that performs a task for OS is called a command. These commands are issued from the prompt of OS.
The arguments that are associated with the commands are as follows −
argc - argument count.
argv - argument vector.
argc − It holds the total number of arguments passed from the command prompt.
argv − It is a pointer to an array of character strings contains names of arguments.
For example,
c: |> sample. Exe hello how are you arguments
Here,
argc = 5
argv[0] = sample.exe
argv[1] = hello
argv [2] = how
argv[3] = are
argv[4] = you
Example
Following is the C program for command line argument −
#include<stdio.h> main ( int argc, char *argv[ ]){ int i; clrscr( ); printf (" no. of arguments at command p = %d", argc); printf (" arguments given at prompt are
"); for ( i = 1; i <argc; i++) printf ("%s
", argv[i]); getch( ); }
Output
To run a C program with command-line arguments −
Compile the program
Run the program
Go to the command prompt and give the input as shown below.
c:|> sample.exe hello how are you. No. of arguments given at prompt is = 5 Arguments given at command prompt are: hello How Are You
- Related Articles
- How do you pass a command line argument in Java program?
- Command Line arguments in C#
- Command line arguments in C/C++
- Command line arguments example in C
- Parsing Command Line Parameters in C++ Program
- How to send individual elements as an argument in C language?
- How to pass entire array as an argument to a function in C language?
- How to send an entire array as an argument in C language?
- How to Parse Command Line Arguments in C++?
- What is a malloc function in C language?
- What is a multidimensional array in C language?
- What is a simple assertion in C language?
- What is "Argument-Dependent Lookup" ("Koenig Lookup") in C++?
- Command Line Interpreters
- What is malloc in C language?

Advertisements