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

Is c language easy to learn?
The ease of learning C language depends on your prior programming experience and familiarity with certain concepts. For beginners, C can be challenging due to its syntax and manual memory management. However,...
Vikash
0 0
6
How many programs are in the C language?
Here, we have provided 100+ C programming examples in different categories like basic C Programs, Fibonacci series in C, String, Array, Base Conversion, Pattern Printing, Pointers, etc.
Muskan
0 0
6
Is it good practicing c++ in code blocks instead of turbo c++?
Practicing/working on Turbo C++ is always good..because its hard to do comparatively 'code blocks'. seems 'code blocks' has been designed by considering the latest working tools(like Visual Studio from...
Santosh
How do you override a defined macro?
We can use the #ifdef and #undef directive to undefine a previously defined macro.
Sharmistha

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

Ask a Question

Related Lessons

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

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)...

Functions In C Programming
A C-language program is nothing but collection of Function, these are the building blocks of a ‘C’ program. Generally, a function mans a task. “Function is a...

Programing Languages Learning Tricks
You want to learn that new language or library or framework as soon as possible, right? That’s understandable. Fortunately, there are a handful of tips that can help you to better retain all of that...

Harshal G.

0 0
0

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