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

What are pointers in C language?
Hi Imran, Hope you are doing good. Are you looking for short answer or long answer? :) Pointers in C are variables that store memory addresses. They point to the location of another variable, allowing...
Imran
0 0
7
What are the advantages of using C over C++?
C++ is a object oriented programming language
Rekha
0 0
5
How would you round off a value from 1.66 to 2.0?
using ceil function. i.e. ceil(1.66)
Dhanya
0 0
6
What is the program for print calendar?
int fm(int date, int month,year) { int fmonth, leap; //leap function 1 for leap & 0 for non-leap if ((year % 100 == 0) && (year % 400 != 0)) leap = 0; else if (year % 4 == 0) ...
Yatindra

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

Ask a Question

Related Lessons

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Memory Layout of C Programs
A typical memory representation of C program consists of following sections. Text Segment: A text segment, also known as a code segment or simply as text, is one of the sections of a program in an object...

Variables
Variables in C Language:A variable is a name that may be used to store a data value. Unlike constant, variables are changeable, we can change value of a variable during execution of a program. A programmer...

C Program to print Block Letter and Small Case Alphabets using C
/* WAP to print Block Letter and Small Case Alpahbets using C*/ //Hint:use ascii code(value) to print #include#include void main(){ int i; clrscr(); //Block Letters Alphabets printf("Block Letters Alphabets\n");...
S

INTRODUCTION TO PROGRAMMING LANGUAGES
Language is a medium for communication. If we want to perform anything with another person, we can know the human language as a human being. Similarly, if we want to perform anything with a computer, we...

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