Nearby lessons

85 of 124

C - Pointers

Pointers is one of the foundational topics in C programming. This lesson explains What is a Pointer? and Declaring Pointers with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

What is a Pointer?

Every variable in C lives at some memory address. A pointer is a special variable that stores the address of another variable — it 'points to' that variable.

Think of it like a map that tells you where a house is: p is the map, and &a is the house's location.

In simple words: a normal variable stores a value; a pointer stores a house address. With the address you can go to the house (*p) and read or change what is inside.
Example01
CCode Cell
1int a = 10; // a is stored somewhere in memory
2int *p; // p is a pointer - it will store an address
3p = &a; // p now holds the address of a (points to a)

Declaring Pointers

The * in the declaration says: this variable is a pointer. The type (int, float, char) tells C what kind of value the pointer points to.

Example02
CCode Cell
1int *ip; // pointer to an integer
2float *fp; // pointer to a float
3char *cp; // pointer to a character
📝 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

2 Questions
Progress: 0 / 2