C Pointers and Arrays

C Tutorial

 C Pointers and Arrays (Beginner → Advanced)

Pointers and arrays are closely related in C.
Understanding this relationship is mandatory for DSA, memory concepts, embedded systems, and interviews.


 Relationship Between Pointers and Arrays

->Array name itself is a pointer to the first element of the array.

  • arr → address of arr[0]

  • &arr[0] → same address


 Array Access Using Pointer Arithmetic


 

  • Pointer automatically moves by sizeof(int)

 Difference: arr vs &arr

ExpressionMeaning
arrAddress of first element
&arrAddress of entire array
arr + 1Next element
&arr + 1Next array block
  •  Interview-tricky concept

 Pointer vs Array (Important )

FeatureArrayPointer
Memory allocationFixedDynamic possible
SizeFixedSame as address
Can change address No Yes
ArithmeticLimitedFull

Arrays Passed to Functions (Always by Reference)


 

  •  No array copy is made
  •  Fast and memory efficient

 Pointer to Array vs Array of Pointers

 Pointer to Array


 

 Array of Pointers

int *p[3];
  •  Very common interview confusion

 Pointers with Multidimensional Arrays


 

  •  Pointer must know column size

 Array of Pointers (Strings Example)


 

  •  Used in command-line arguments

 Pointer Arithmetic Rules

  •  Pointer + pointer (invalid)

 Common Mistakes

  •  Confusing array with pointer
  •  Using sizeof(pointer) instead of sizeof(array) 
  •  Wrong pointer type for 2D arrays
  •  Accessing out-of-bounds memory

 Interview Questions (Must Prepare)

  1. Relationship between pointer and array

  2. Difference between array and pointer

  3. What is arr vs &arr?

  4. How arrays are passed to functions?

  5. Pointer to array vs array of pointers

  6. 2D array pointer declaration


 Real-Life Use Cases

  • Dynamic memory management

  • String handling

  • Data structures

  • Embedded buffers

  • Command-line arguments


 Summary

  •  Array name acts as pointer
  •  Pointer arithmetic enables fast access
  •  Arrays passed by reference
  •  2D arrays require correct pointer type
  •  Extremely important for DSA & interviews

You may also like...