Command line arguments
Command line arguments : Command line arguments are simply arguments that are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution.
Syntax : int main(int argc, char *argv[] )
Here, argc counts the number of arguments. It counts the file name as the first argument.
The argv[] contains the total number of arguments. The first argument is the file name always.
Example 1 : Program file : x.c
#include<stdio.h> #include<conio.h> void main() { printf("GoEduHub Welcomes You"); } |
---|
Open command prompt and compile the file using "gcc file_name.c" then, after compilation of file it will create a ".exe" file my file is "a.exe" . It will display content of your file .

Example 2 : program file : X.c
#include <stdlib.h> #include <stdio.h> int main(int argc, char** argv) { printf("Program name is: %s\n", argv[0]); printf("First argument is: %s\n", argv[1]); printf("second argument is: %s\n", argv[2]); printf("third argument is: %s\n", argv[3]); return 0; } |
---|
Open command prompt and compile the file using "gcc file_name.c" then, after compilation of file it will create a ".exe" file my file is "a.exe" . now write "a arg1"

For more RTU/BTU II Sem Computer Programming Lab Experiments CLICK HERE