Nearby lessons
93 of 124C - Pointers and Arrays
Pointers and Arrays is one of the foundational topics in C programming. This lesson explains Complete Program 3 — Pointers and Arrays with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Complete Program 3 — Pointers and Arrays
The name of an array is actually the address of its first element. So pointers and arrays are very close friends:
In simple words: the array name is the address of the first locker. So p = a makes p point to locker 0, and *(p + 1) reaches locker 1 — exactly like a[1].
Trainer's Note: Pointer arithmetic follows the type size: p + 1 on an int pointer moves forward by sizeof(int) bytes, not 1 byte. That is why *(p + 1) reaches the next array element correctly.
Example01
📝 Key Takeaways
- A pointer stores the address of a variable; it 'points to' it.
- & gives the address; * gives the value at an address.
- Each concept has its own program: & and *, change via pointer, arrays, swap, NULL.
- Array name = address of the first element; *(p+i) walks the array.
- Call by reference uses & and * so a function can change original variables.
- Swap is the classic call-by-reference example.
- Always check for NULL before using a pointer.
- (Advanced pointer topics — pointers to functions, linked lists — are beyond beginner scope.)
🧠 Test Your Knowledge
1 QuestionsProgress: 0 / 1