Launch your tech mastery with us—your coding journey starts now!
Course Content
Basic Syntax and Data Types
0/2
Arrays and Strings
0/2
Structures in C
0/1
Dynamic Memory Management
0/1
Command Line Arguments
0/1
Preprocessor Directives
0/1
C Programming

Command Line Arguments

Definition:
Command line arguments allow you to pass values to your main() function when running the program from a terminal.

Syntax:

int main(int argc, char *argv[])

  • argc – Argument count (number of arguments)
  • argv[] – Argument vector (array of strings)

Example:

#include <stdio.h>

int main(int argc, char *argv[]) {

    for (int i = 0; i < argc; i++) {

        printf(“Argument %d: %s\n”, i, argv[i]);

    }

    return 0;

}

Run via terminal: ./program Hello World
Output:
Argument 0: ./program
Argument 1: Hello
Argument 2: World