What is the difference between:
int* a = new int[w]; int** b= new int*[w]; and what exactly does this mean: int*[w] and int[w]?
In the first case, you're dynamically creating an array of int with w elements. In the second, you create an array of int * with w elements.
The notations int*[w] and int[w] are the types mentioned above: an array of int * of size w, and an array of int of size w respectively.
int. If you initialize each of those pointers to point to an array of int, then you can treat it more or less as a 2D array — but it still isn't a 2D array (matrix).int* a = new int[w] This first example dynamically allocates w integers.
int** b = new int*[w] The second example dynamically allocates w pointers to integers.
whas to be defined as a const and not as a variable.int w = 6; int *a = new int[w]; int **b = new int*[w];), even withg++ -O3 -g -std=c++11 -Wall -Wextra -Werror -pedantic …. That's not the same as claiming "the C++ standard allows it", but the-pedanticshould trigger a warning (error because of-Werror) if it is in contravention of the standard.int w = 6; int vla_a[w]; int *vla_b[w];then you'd be playing with VLAs, and that is not allowed by the C++ standard but G++ does allow it unless you specify-pedantic. As it stands, with thenew, you're allocating a dynamic array with a dynamic size — the analogue ofint *a = malloc(w * sizeof(int));in C. Variable sizes are allowed inint *a = new[w];, I'm practically certain.