basic of array and pointer

This is a discussion on basic of array and pointer within the C Programming forums, part of the General Programming Boards category; I have this below code
Code:
int main()
{
int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, ...

is possible but it is bad syntax (will generate a gcc warning) and no one would really do this in real life. If you try to access the memory pointed to by this pointer now it will segfault. However, the next printf statement does not do that; it prints the "memory address" stored in the pointer itself. In this case, it is set to "4" which is not a valid memory address. So this is misuse of the type. If you check the address pointed to this way:

Code:

printf("%p\n",pointer);

It will give you that (invalid) address in hex (0x4).

The second example would be proper use of an int pointer:

Code:

pointer = &x[4];
printf("%d \n", *pointer);

The first line assigns the address of (&) x[4] to "pointer". So now if you check the address contained in pointer (with "%p" again), you will get a real address (something like "0x7fff959dccf0"); that is the address of x[4]. "pointer" points to x[4]. So when you ask for the value of the memory pointed to by dereferencing (*):