Home / Programs / Command Line Arguments Basic Program
🚀 Programming Example

Command Line Arguments Basic Program

👁 544 Views
💻 Practical Program
📘 Step Learning
Program to print all value of command-line argument once we get the value from the command line we can use them to solve our problem

💻 Program Code

// Program to print all value of
// command line argument
// once we get the value from command
// line we can use them to solve our problem
#include <stdio.h>

int main(int argc, char *argv[])
{
int a,b;
int i;
if(argc<2)
{
    printf("please use \"prg_name value1 value2 … \"\n");
    return -1;
}

for(i=1; i<argc; i++)
{
    printf("arg[%2d]: %d\n",i,atoi(argv[i]));
}

return 0;
}
                        

🖥 Program Output

11 22 33
                            

📘 Explanation

arg[ 1]: 11 arg[ 2]: 22 arg[ 3]: 33
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.