previous | start | next

Summary Example: The Program

Here is the code for printCh:

int main(int argc, char * argv[])
{
  char ch;
  if ( argc < 2 ) {
     ch = 'A';
  } else {
     ch = argv[0][0];
  }

  printf("argc = %d\n", argc);
  for(i = 0; i < argc; i++) {
     printf("argv[%d] = %c\n", i, ch);
  }
  return 0;
}

How does this program get values for argc and argv if executed from a shell?



previous | start | next