0

This is a beginner question, but I'm just trying to get comfortable with pointers to pointers here.

If I create an array of arrays like this:

    int n; // n lines
    cin>>n; // read in first line, number of lines in array of arrays
    int **arrays =new int *[n];  // create pointer of pointer of size n
    for (int i = 0; i < n; i++) {  // looping through n lines to fill each
        int sz;  // first int of each line is line size
        cin>>sz; // read in line size
        int *line = new int [sz];  // create line of size sz
        for (int j = 0; j < sz; j++) {  // loop through individual ints in line
            int x; // declare individual int
            cin>>x; // read in individual int
            line[j] = x; // fill line with each x
        }
        *(arrays+i)=line; // fill lines of 2D array
    }

/*
Sample input:

2       // n lines 
3 1 5 4  // first int of each line is line length
5 1 2 8 9 3 
*/

After I've created int **arrays Is there any way to obtain information after the fact on the length of each subarray, something like a strlen() for int*'s, so that I can print it out using a double for loop? Or if I wanted to print it out would I need to keep track of the length of each line in the first place?

Austin
  • 6,921
  • 12
  • 73
  • 138
  • The question refered to by juanchopanza does not have an accepted answer. – Andreas Apr 02 '16 at 08:49
  • The answer is no. There are differences between array and pointer, although often used in similar way. This I believe is a good beginners introduction to difference between array and pointer adn should give answer to your question: http://stackoverflow.com/questions/1461432/what-is-array-decaying – Andreas Apr 02 '16 at 08:52

0 Answers0