SlideShare a Scribd company logo
1 of 6
Command line arguments
Command Line Arguments
● The arguments passed from command line are called command line
arguments.
● Command line arguments are simply arguments that are specified after the
name of the program in the system’s command line, and these argument
values are passed on to your program during program execution.
● Arguments are handled by main() function.
Components of Command Line Arguments
There are 2 components of Command Line Argument in C++:
1. argc: It refers to “argument count”. It is the first parameter that we
use to store the number of command line arguments. It is
important to note that the value of argc should be greater than or
equal to 0.
2. agrv: It refers to “argument vector”. It is basically an array of
character pointer which we use to list all the command line
arguments.
Properties of Command Line Arguments:
1. They are used to control program from outside instead of hard coding
those values inside the code.
2. argv[argc] is a NULL pointer.
3. argv[0] holds the name of the program.
4. argv[1] points to the first command line argument and argv[n] points last
argument.
Syntax:
int main(int argc, char *argv[] )
Example of C Command Line Arguments
1. #include <iostream>
2. using namespace std;
3. int main(int argc, char** argv)
4. {
5. cout << "You have entered " << argc << " arguments:" <<"n";
6. for (int i = 0; i < argc; ++i)
7. cout << argv[i] << "n";
8. return 0;
9. }
Input and Output :
[19mx101@shavakpsg ~]$ gedit arg.cpp
[19mx101@shavakpsg ~]$ g++ -o arg arg.cpp
[19mx101@shavakpsg ~]$ ./arg Titum and thank you
You have entered 5 arguments:
./arg
Titum
and
thank
you
[19mx101@shavakpsg ~]$

More Related Content

What's hot (20)

Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Python functions
Python functionsPython functions
Python functions
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Sorting
SortingSorting
Sorting
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Packages in java
Packages in javaPackages in java
Packages in java
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 

Similar to Command line arguments

COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++Harshita426026
 
Task mo7drt File Organization.docx
Task mo7drt File Organization.docxTask mo7drt File Organization.docx
Task mo7drt File Organization.docxMohamedAyman183185
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#Ali Hassan
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
23_1-Command line Arguments.pptx
23_1-Command line Arguments.pptx23_1-Command line Arguments.pptx
23_1-Command line Arguments.pptxGandavadiVenkatesh1
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main웅식 전
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | LearnbayLearnbayin
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++Shobi P P
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobolSrinimf-Slides
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 

Similar to Command line arguments (20)

COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++
 
Task mo7drt File Organization.docx
Task mo7drt File Organization.docxTask mo7drt File Organization.docx
Task mo7drt File Organization.docx
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
23_1-Command line Arguments.pptx
23_1-Command line Arguments.pptx23_1-Command line Arguments.pptx
23_1-Command line Arguments.pptx
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | Learnbay
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 

More from Ashok Raj

Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++Ashok Raj
 
How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ramAshok Raj
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance ComputerAshok Raj
 
Super computers
Super computersSuper computers
Super computersAshok Raj
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its typesAshok Raj
 
Microprocessor
MicroprocessorMicroprocessor
MicroprocessorAshok Raj
 
Mother board
Mother boardMother board
Mother boardAshok Raj
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systemsAshok Raj
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stackAshok Raj
 

More from Ashok Raj (11)

Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ram
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance Computer
 
Super computers
Super computersSuper computers
Super computers
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its types
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Mother board
Mother boardMother board
Mother board
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stack
 

Recently uploaded

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Recently uploaded (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

Command line arguments

  • 2. Command Line Arguments ● The arguments passed from command line are called command line arguments. ● Command line arguments are simply arguments that are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution. ● Arguments are handled by main() function.
  • 3. Components of Command Line Arguments There are 2 components of Command Line Argument in C++: 1. argc: It refers to “argument count”. It is the first parameter that we use to store the number of command line arguments. It is important to note that the value of argc should be greater than or equal to 0. 2. agrv: It refers to “argument vector”. It is basically an array of character pointer which we use to list all the command line arguments.
  • 4. Properties of Command Line Arguments: 1. They are used to control program from outside instead of hard coding those values inside the code. 2. argv[argc] is a NULL pointer. 3. argv[0] holds the name of the program. 4. argv[1] points to the first command line argument and argv[n] points last argument. Syntax: int main(int argc, char *argv[] )
  • 5. Example of C Command Line Arguments 1. #include <iostream> 2. using namespace std; 3. int main(int argc, char** argv) 4. { 5. cout << "You have entered " << argc << " arguments:" <<"n"; 6. for (int i = 0; i < argc; ++i) 7. cout << argv[i] << "n"; 8. return 0; 9. }
  • 6. Input and Output : [19mx101@shavakpsg ~]$ gedit arg.cpp [19mx101@shavakpsg ~]$ g++ -o arg arg.cpp [19mx101@shavakpsg ~]$ ./arg Titum and thank you You have entered 5 arguments: ./arg Titum and thank you [19mx101@shavakpsg ~]$