Assuming input is valid,
- atoi(argv[2] - why is it 2 |
argv[0] is the name of the program
argv[1] is the first command line argument
argv[2] is the second command line argument.
In this case, max is initialised with 4838.
Similarly, pos is the index of the number.
- for (int i=4; i<=8; i=i+2) |
This is a loop to compare all the other numbers to the current max number.
int i=4, to start comparing from the second number in argv.
i<=8, the last number to compare is at index 8 in argv.
i=i+2, remember that each number is 2 positions away from the previous
max = atoi(argv[i]);
pos = i; |
Updates the highest number and the index of that number.