Home > Backend Development > C++ > In C language, command line parameters refer to parameters passed to the program through the command line when the program is running.

In C language, command line parameters refer to parameters passed to the program through the command line when the program is running.

PHPz
Release: 2023-09-22 15:01:02
forward
878 people have browsed it

In C language, command line parameters refer to parameters passed to the program through the command line when the program is running.

Executable instructions that perform operating system tasks are called commands. These commands are issued from the operating system prompt.

The parameters associated with the command are as follows:

  • argc - Argument count.

  • argv - Argument vector.

argc - It holds the total number of arguments passed from the command prompt.

argv - It is a pointer to a character string array containing the names of the arguments.

For example:

c: |> sample. Exe hello how are you
   arguments
Copy after login

Here,

  • argc = 5

  • argv[0] = sample.exe

  • argv[1] = hello

  • argv [2] = how

  • argv[3] = are

  • argv[4] = you

Example

Here is the C program for command line arguments:

#include<stdio.h>
main ( int argc, char *argv[ ]){
   int i;
   clrscr( );
   printf (" no. of arguments at command p = %d", argc);
   printf (" arguments given at prompt are </p><p>");
   for ( i = 1; i <argc; i++)
      printf ("%s</p><p> ", argv[i]);
   getch( );
}
Copy after login

Output

Using command line arguments Run the C program:

  • Compile the program

  • Run the program

  • Go to the command prompt and Enter as shown below.

c:|> sample.exe hello how are you.
No. of arguments given at prompt is = 5
Arguments given at command prompt are:
hello
How

Are
You
Copy after login

The above is the detailed content of In C language, command line parameters refer to parameters passed to the program through the command line when the program is running.. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template