I am just learning about command line arguments in my class and I do not fully understand them yet. I understand that they are stored in *argv[], and are counted by argc, but I do not understand their purpose or where they come from. I have attempted to write a program in C ++ to find the sum of command line arguments input by a user and have included the code below, but I have no idea if it is correct or how I would even test it. If someone could give me a simple description of what they are and how to access them it would be greatly appreciated.
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
double sum = 0;
for(int counter = 0; counter < argc; counter ++)
{
sum += atof(argv[counter]); //compact form of : sum = sum + atof(argv[counter]);
}
cout << "Sum = " << sum << endl;
}