Difference between array and pointer in C/C++

The difference between pointer and array in C/C++ is tabulated below.
PointerArray
1. A pointer is a place in memory that keeps the address of another place inside
1. An array is a single, pre-allocated chunk of contiguous elements (all of the same type), fixed in size and location.
2. Pointer can’t be initialized at definition.
2. Array can be initialized at definition. Example
int num[] = { 2, 4, 5}
3. Pointer is dynamic in nature. The memory allocation can be resized or freed later.
3. They are static in nature. Once the memory is allocated, it cannot be resized or freed dynamically.
4. The assembly code of Pointer is different than Array
4. The assembly code of Array is different than Pointer.
SHARE Difference between array and pointer in C/C++

You may also like...

10 Responses

  1. an array is defined as ____ rather then a normal pointer ?

  2. Its good to know about the difference between two, such an informative article.

  3. Anonymous says:

    An array is defined as constant pointer whose address cant be changed.

  4. Anonymous says:

    Pointers can be initialized at the definition right?
    int n = 10;
    int *ptr = &n;

  5. Unknown says:

    thanks for saving time 🙂

  6. Anonymous says:

    you cannot initialize a pointer with a constant value at the time of declaration.
    Ex: int *ptr = 10; is NOT POSSIBLE

  7. Anonymous says:

    helpufull

Leave a Reply

Your email address will not be published.

Share