1. ## A question about Arrays and Pointers

Hey,

I am wondering what this is:

Code:
`int* a`
- Is it a array of int* or
- is it a pointer to an array of ints?

I am asking because you can actually deepcopy multidimensional arrays using memcopy, while you cannot using type**.

After some research I experienced that an multidimensional array is stored as a coherent "object". There are no pointers to adresses stored.

So I am wondering what exactly happens when I pass an array as an type**.
Does C create pointers to actualy locations, because if not: How does the computer know the size of the stored arrays?

Thank you! 2. "a" is a static array of "int*" and of size "3".

A multi-dimensional array in C is just 1-D in memory. For example, the following two arrays are equivalent:
Code:
```#define COLUMNS 3
#define ROWS 4

int a[ROWS][COLUMNS];
int b[ROWS*COLUMNS];

a = 123;
b[2*COLUMNS + 1] = 123;```
Those are the so-called 2-D arrays. What you have here is an array of pointers. Sure, it can be used as a 2-D array, but don't assume that they are equivalent.

because if not: How does the computer know the size of the stored arrays?
It doesn't. 3. This is a 3 element array of pointer to ints
Code:
`int* a;`
Used like this...
Code:
```int *a; /* Notice that the * is usually put next to the variable name */
int x,y,z;
x = 1;
y = 2;
z = 3;
a = &x;
a = &y;
a = &z;```
If you want to create a pointer to an array of int
Code:
```int a = {0};
int (*b);
b = &a;```
http://users.ece.utexas.edu/~ryerrab...eclPrimer.html
How does the computer know the size of the stored arrays?
If it is defined in scope you can use
Code:
```int apple = {0};
size_t appleSize;
appleSize = sizeof(apple)/sizeof(apple);```
Otherwise you need to pass the size of the array into the functions that you wish to use, like the second argument in fgets. Code:
`int *a;`
Is an array of 3 pointers to int. And this:
Code:
`int (*a);`
Is a pointer to an array of 3 ints.

This:
Code:
`int **a;`
Is a pointer to a pointer which points to an int.

The three declarations are completely different from each other.

In the context of a function, main(), for exemple, the argument argv can be writen as one of these two:
Code:
```int main( int argc, char *argv[] )
int main( int argc, char **argv )```
They are equivalent because any array in the argument declaration is passed as a pointer. So, if you have something like this:
Code:
```// array of 3 ints.
int v = { 0, 1, 2 };

// array of 3 pointers to ints.
int *a = { &v, &v, &v };

// Prototype. accepts a pointer to a pointer to int.
int f( int **pp );

// Calls f() with a pointer which points to pointers to ints.
f( a );```
Here a is converted to a pointer to the first element of the array (identified by the symbol a). Which is the same as:
Code:
`f(&a);`
In the context of memset(), for example, the pointer in the argument points to a buffer which will be filled. A pointer of type int ** will be a pointer which points to an array of pointers, so the pointers pointed will be filled. Let's say:
Code:
`memset( ( void * )a, 0, sizeof a );`
This will fill the array a with zeroes, so a = a = a = 0 (which is the same as NULL). Notice the array v remains untouched. 5. Understood! Thank you! Popular pages Recent additions array, arrays, pointers, stored, wondering 