Search This Blog

Wednesday 2 January 2013

What is the difference between a pointer and an array?

What is the difference between a pointer and an array?

Pointers are variable. You point to one variable, and after sometime you start pointing to another variable with the same pointer.
Example:
int x = 1;
int *p = &x;
//in the next line you can say
*p = &b; // if b has been initialized.

Array name is the address to the first index of array. Array name is a CONSTANT Pointer => You cannot do a = a + 1; if a is an array. It will generate an error since it always point to same location.
When we do for example cout << *(a+1); (a is arraY) We give an offset and elements at 2nd index is printed. a still points to the first location.

1 comment:

  1. Right now it sounds like BlogEngine is the best blogging platform
    out there right now. (from what I've read) Is that what you're using on your blog?


    Check out my blog post ... bmi index chart

    ReplyDelete