What is the difference between an array and a pointer in C?

ArrayPointer
Fixed block of memory with its own sizeA variable which stores an address
sizeof(arr) gives the total bytessizeof(p) gives the pointer size
Name cannot be changed to point elsewhereCan point to any place
Memory is allocated automaticallyMemory is given by the programmer, or it points to an existing one
#include <stdio.h>

int main(void) {
    int arr[5] = {1, 2, 3, 4, 5};
    int *p = arr;

    printf("%zu %zu\n", sizeof(arr), sizeof(p));
    printf("%d %d\n", arr[2], p[2]);
    return 0;
}

Output:

Output of the above program is

20 8
3 3

The array name acts like a pointer in most expressions (it “decays”), and that is why they look alike. See Pointers and Arrays.


Learn more about the similar topics:
Tutorials
C Pointers
C Pointer Arithmetic
C Pointer to Pointer
C Pointers and Arrays
C Pointers and Functions
C Dynamic Memory Allocation
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is a pointer in C?
What is a NULL pointer in C?
What is the difference between malloc() and calloc() in C?
What is a memory leak in C and how to avoid it?
What is a dangling pointer in C?
What is the difference between an array and a pointer in C?
What is a void pointer in C?