Course Content

  • clarguments

Course Content


  • #include <stdio.h>
  • void main(int argc, char *argv[] ) {
  • printf("Program name is: %s\n", argv[0]);
  • if(argc < 2){
  • printf("No argument passed through command line.\n");
  • }
  • else{
  • printf("First argument is: %s\n", argv[1]);

Run an executable from the "Command Prompt" in Windows or the "DOS prompt" in older versions of Windows to test command line inputs. You can also utilise command line parameters in programme shortcuts or when using Start -> Run to start an application.

The arguments passed to the operating system's command line by the user during execution are known as command line arguments. Previously, we utilised main() routines that took no arguments. The main() method takes care of these command line inputs.

We commonly define main() with two arguments to pass command line arguments: the first argument is the number of command line arguments, and the second argument is a list of command line arguments. The argc value should not be negative. argv(ARGument Vector) is a character pointer array that contains all of the arguments.

A collection of null-terminated strings that reflect command-line parameters entered by the program's user. By convention, argv[0] is the command used to start the programme. The first command-line argument is argv[1]. argv[argc - 1] is the last argument from the command line, and argv[argc] is always NULL.

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere