Mod 3 cmdline arg
Mod 3 cmdline arg
MODULE 3
COMMAND LINE ARGUMENTS
Command Line Arguments in C
• Command line arguments are used to pass values to a C program
when it is executed (through the terminal or command prompt).
• They allow users to influence the behavior of the program
dynamically without modifying the code.
• These arguments are passed to the main() function and can be
accessed directly within it.
• int main(int argc, char *argv[])
Argument Count: total number of arguments passed
argc
(including program name)
Argument Vector: array of strings representing the
argv[]
arguments
Key Concepts
• argv[0]: name of the program (by default)
• argv[1] to argv[argc-1]: actual command line arguments
• All command line arguments are strings (character arrays)
• Must be converted using functions like atoi(), atof() for numerical
operations
Example 1
#include <stdio.h>