Variables and pointers

Consider the following program.


#include<iostream>

const char endOfCharArray = '\0';

int main(int argc, char** argv) {
  using namespace std;
  int ret = 0;
  if (argc < 2) {
    cerr << "error: no arguments on cmd line" << endl;
    ret = 1;
  } else {
    for(int i = 0; i < argc; i++) {
      while(*(argv[i]) != endOfCharArray) {
        cout << *(argv[i]);
        argv[i]++;
      }
      cout << endl;
    }
  }
  return ret;
}

(a) List the variables in the program and their types. (b) List the pointers in the program and their types. (c) How many pointers are there in the program when it is run with the command line ./variables_pointers 123 456 789? (d) Edit, save, build and run the program with the command line above. What is the output?



Subsections

Leo Liberti 2008-01-12