Most of the time, pointer and array accesses can be treated as acting the same, the major exceptions being:
1. the sizeof operator
- sizeof(array) returns the amount of memory used by all elements in the array
- sizeof(pointer) only returns the amount of memory used by the pointer variable itself
2. the & operator
- array is an alias for &array and returns the address of the first element in the array
- &pointer returns the address of the pointer
3. a string literal initialization of a character array
- char array = “abc” sets the first four elements in array to ‘a’, ‘b’, ‘c’, and ‘\0’
- char *pointer = “abc” sets the pointer to the address of the “abc” string (which may be stored in read-only memory and thus unchangeable)
4. Pointer variable can be assigned a value whereas an array variable cannot be.
5. Arithmetic on pointer variable is allowed.
6. Array is a collection of similar data types while the pointer variable stores the address of another variable.
Please refer Difference between pointer and array for more details.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!