Are pointers and arrays any different in C?

arrays, c, pointers

Solution

Your code snippet is correct. However, pointers and arrays in C are indeed different. Put simply "the pointer to type T" is not same as "the array of type T".

Please have a look at C Faq discussing Pointers & arrays to get a better understanding of this.

Problem

I'm writing a small C program to do some number crunching, and it needs to pass around arrays between functions. The functions should accept and return pointers, right? For example, this (I know it may not be the most efficient thing): ``` int* reverse(int* l, int len) { int* reversed = malloc(sizeof(*reversed)*len); int i, j; for (i = 0, j = len-1; i < len; i++, j--) { reversed[j] = l[i]; } return reversed; } ``` Am I using pointers right?

Original source

Related problems