23 lines
563 B
C
23 lines
563 B
C
#include <stdio.h>
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
int array[] = {1,2,3,4,5,42};
|
|
int array2[] = {4,3,2,1};
|
|
int *pointer = array;
|
|
|
|
// The access of an array and a pointer are equivalent
|
|
printf("*array = %d, *pointer= %d, array[0] = %d pointer[0] = %d\n",
|
|
*array, *pointer, array[0], pointer[0]);
|
|
|
|
// you can't do this:
|
|
// array = array2;
|
|
|
|
// you can do this:
|
|
pointer = array2;
|
|
|
|
// There are some minor differences between pointers an arrays.
|
|
printf("sizeof(array) = %d, sizeof(pointer)= %d",
|
|
sizeof(array),sizeof(pointer));
|
|
}
|