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

Which websites are best to learn C programming?
There are several reputable websites where you can learn C programming. Here are some popular ones: GeeksforGeeks (geeksforgeeks.org): Offers a wide range of tutorials, practice problems, and articles...
Sarath Chandra
0 0
5
How do I start learning C programming and finish it in one month?
Please follow the book "C Programming" by Detal & Detal. Its an applied book easy to understand compare to others. U may also learn through online free tutorial.
Pallavi
0 0
8
Can a function defined inside another function?
No, you can call other function(s) inside a function but you cannot define a new function in it.
Kamal
0 0
8
What is the output of the below: printf("%d", printf("Hello"));
The output would be as follows: Hello5 Reason: 'printf( )' not only prints a given strings, but it also returns a number which is the count of the number of characters that it has successfully printed...
Pravalika
What is C language?
it is a computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations
Uday

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

Ask a Question

Related Lessons

4 Things Every Tech Startup Needs to Know About The Coaching Industry
Knowledge on any subject is widely available to those who wish to learn. However, just gathering knowledge from other people doesn’t guarantee results in business. Results come from applying what...

Be prepared to get trained--init
Before starting the training,students must be mentally prepared for acceptance of new knowledge. Students must attend training with open minded forgetting the position they are working.This will help...
S

Smartnub Softsolutions

0 0
0

C Program-Error Handling[Program Exit Status]
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main Function void main(){ int dividend=20; int divisor=5; int quotient; //Function for clearing screen clrscr();...

C Program-Temperature [conversion from farenheit to degree celsius]
//WAP to convert temperture from farenheit into degree celsius //Header files#include<stdio.h>#include<conio.h> //Main functrion void main(){ //Variable declaration of type float float...

C++ Program-Working with constant using #define preprocessor
//Header Files #include#include // using #define preprocessor for defining a constant#define len 10#define br 5#define rad 3#define NEWLINE '\n' //Main function void main(){ int area_r; float area_c; //Function...

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