Hi,
in the next example code:

#include <iostream>;
using namespace std;
#include <iomanip>;

int main(int argc, char *argv[])
{
  for(int i = 1; i <= 28; i++)
  {
     cout << setw(3)<< i;
    if(i%7 == 0)
    {
        cout << endl;    
    }    
  }
  system("PAUSE");	
  return 0;
}

i compiled and i have no errors, but i want understand two lines:

1- (int argc, char *argv[]) .. what that refer to ..?
2- if (i%7 == 0)

Recommended Answers

All 3 Replies

1- (int argc, char *argv[]) .. what that refer to ..?

You'll find more about this here.

2- if (i%7 == 0)

% is the modulo operator, it returns the remainder of a division, for example 14%7 will return 0, but 15%7 will return 1.

1.argc stands for argument count. It's the number of arguments passed to the program via the command-line. The first agument is always the name of the program it's self (or rather, the path used to execute it).

An easy way to understand this is with the followign program:

#include <stdio.h>

main (int argc, char *argv[])
{
    printf("%d\n", argc);
}
  1. argv is an array that contains the command-line arguments that argc counts.

An example... possibly a bit hard to understand... Notice how **argv works exactly the same as *argv[] does:

main (int argc, char **argv)
{
    int i = 0, j = 0;
    for (; i < argc; i++)
        for (; j < strlen(argv[i]); j++)
            printf("argv[%d][%d] is: %c\n", i, j, argv[i][j]);
}

1. Since you are new to C++, I doubt you will really need to use that argc stuff but like that first post says, you can find information if you really need in that link.

2. "If you divide i by 7 and have the remaider 0 then do something."

if (i) modular (7) is equal to (0) then
{
do this
}


% stands for mod which is basically remainder and == is used to check the right side values against the left side (or vise versa but you get the point...)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.