UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is a command-line argument?

Asked by Last Modified  

Follow 3
Answer

Please enter your answer

C language Faculty (online Classes )

Command-line arguments are simple parameters that are given on the system's command line, and the values of these arguments are passed on to your program during program execution. When a program starts execution without user interaction, command-line arguments are used to pass values or files to...
read more
Command-line arguments are simple parameters that are given on the system's command line, and the values of these arguments are passed on to your program during program execution.
When a program starts execution without user interaction, command-line arguments are used to pass values or files to it.
 
read less
Comments

You might be familiar with the following simple way to define the main function: int main() {/* blah blah */}but, the more general way to define main is as followsint main(int argc, char* argv) {/* blah blah */}Suppose you compile this file into say a.out, and then if you execute the program from the...
read more

You might be familiar with the following simple way to define the main function:

int main() {
/* blah blah */
}
but, the more general way to define main is as follows

int main(int argc, char* argv[]) {
/* blah blah */
}

Suppose you compile this file into say a.out, and then if you execute the program from the terminal (command prompt) as follows
> ./a.out Hello World

the words Hello, and World are called as command-line arguments, and a.out is the executable (or program).

When executed as mentiond above, the values of argc and argv that the main function recieves would be as follows:

argc gets a value of 3 (the length of the argv array)

argv[0] points to a string with contents "./a.out"

argv[1] points to a string with contents "Hello"

and argv[2] points to a string with contents "World"

Within the main function, you can program different behaviours depending on these variables.

Learn by doing:

Compile the following and execute it with different command-line arguments to see it in action:

#include <stdio.h>
int main(int argc, char* argv[]) {
    int i = 0;
    for(i = 0; i < argc; i++)
        printf("%s\n", argv[i]);
    return 0;
}
read less
Comments

Related Questions

Can one new to programming learn Java, C, or other languages first?
First you can learn C language because it is Mother of all the all advanced language. then we can learn c++,Java,.NET, because all advanced language syntax is inherits from C language. If u r basic is good then u can learn every advanced language.
Agastya
0 0
5
In which program we use character constants?
For the name of months, animal, colors we do use it.
Mona
What is the use of semicolon at the end of every statement?
Computer languages are just like our normal communication languages. Hindi, eng etc. Enable to communicate us with each other. Similarly computer language helps us to communicate with computer. As a full...
Krishna
What are the advantages of using C over C++?
C++ is a object oriented programming language
Rekha
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

C and C++ programming with memory level debugging
Understanding C and C++ programming by using memory level debugging. Step 1: Understand the Memory map of C executable Step 2: Start memory level debugging using popular IDE Step 3: Find the memory...

Bit wise operators in C
Bit Wise Operators Bit Wise operators are manipulates of individual bits with in a word of memory. The bit wise operators can be divided in to three general category. One’s Complement...

Compiler vs Interpreter
Compiler Interpreter Convert all the code into binary format and execute. Convert one statement at a time and execute, then Convert next statement and execute. After conversion, source...

Why Indexing Should Start From Zero In Array ?
Why numbering should start at zero? To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots, fourconventions are open to usa) 2 ≤ i < 13b) 1 < i ≤ 12c)...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more