Questions on argv and argc

  1. What is the value of argc for a program invoked with:
  2. What is the type of variable argc?
  3. What is the minimum value of variable argc?
  4. How many elements are in the argv array associated with the following command line?
    
       % vim prog.source.c
    
    
  5. What is the type of an element of the argv array?
  6. Diagram argv for the command line:
    
       % simulate 100 -12
    
    
  7. Given the command line
    
       % a.out -filename xyz -verbose
    
    
    A. Which string does argv[2] refer to?
    B. What is the value of *(argv[1] + 2) ?
    C.What is the type of the value in part B?
  8. Assume that a program is invoked with the command line:
    
       % prog3 300 5 -Quiet
    
    
    Write a C code fragment that changes the upper case 'Q' to a lower case 'q'.
  9. A program expects to be invoked with a command line represented by
    
       % process <n> <filename>
    
    
    where <n> is replaced by an integer value, and <filename> is the name of a file.

    If the following code represents the C source code that is compiled to be the executable called process, what is wrong with the code?

    
    #include <stdlib.h>
    main(int argc, char *argv[]){
        int n;
    
        n = atoi(argv[1]);
    }
    
    
    Show how to fix this code (fragment).
Copyright © Karen Miller, 2007