Nearby lessons
91 of 124C - NULL Pointer
NULL Pointer is one of the foundational topics in C programming. This lesson explains Complete Program 5 — Safe Use with NULL with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Complete Program 5 — Safe Use with NULL
Always check that a pointer is not NULL before using *p — this avoids the famous segmentation fault (crash) that happens when you dereference a pointer holding an invalid address.
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