KwickAcademy C++ · 7 min · free
Pointers in C
A pointer is a variable that stores the address of another variable; &x gives the address and *p reads the value there.
On screen in this lesson
Memory has addresses
| Memory is a long row of tiny boxes called bytes |
| Every byte has a number: its address |
| An int usually takes 4 bytes |
| &x gives the address of the variable x |
A pointer in memory
| Name | Address | Value stored |
|---|---|---|
| marks | 1000 | 85 |
| p | 2000 | 1000 |
| *p | goes to 1000 | 85 |
Declaring a pointer
| int *p; declares p as a pointer to an int |
| p = &marks; stores the address of marks in p |
| *p means the value at the address in p |
| The pointer type must match the variable type |
& and * side by side
| Symbol | In a declaration | In an expression |
|---|---|---|
| * | makes a pointer | value at address |
| & | not used | address of |
Pointer safety
| An uninitialised pointer holds a garbage address |
| Using it can crash the program |
| Set unused pointers to NULL |
| Check p != NULL before using *p |
Pointer arithmetic
| p + 1 moves to the next element, not the next byte |
| It jumps by the size of the type: 4 bytes for an int |
| p++ and p-- move the pointer forward and back |
| Subtracting two pointers gives elements between them |
Quick answers
Does p + 1 add 1 to the address?
No. It jumps to the next element, 4 bytes for an int.
What does *p = 90 do?
Stores 90 at the address in p, so the variable changes.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
What does &marks give?41 sec
What does int *p declare?42 sec
How far does p + 1 jump for an int?43 sec
What is a[i] the same as?44 secThe full lesson, in text
Hello students, welcome to Kwickprep. Every variable in your program lives at an address, just like your home. What if a variable could store that address? That variable is a pointer. Today we learn memory addresses, declaring and dereferencing pointers, pointer arithmetic, and pointers with arrays and functions.
Think of computer memory as a very long street of houses. Memory is a long row of tiny boxes, and each box is called a byte. Every byte has a number, called its address, just like a house number. A variable uses a few bytes, and an int usually takes four. The ampersand sign before a variable, as in ampersand x, gives its address.
Let us picture it, using easy made-up addresses. The variable marks lives at address one thousand, and stores eighty five. The pointer p lives at address two thousand, and stores one thousand, which is the address of marks. When we write star p, C goes to address one thousand and finds eighty five. Real addresses are long numbers in hexadecimal, and they change every time you run the program.
Here is how to see a real address. The first printf prints the value, eighty five. The second uses percent p, the format for an address, with ampersand marks. The void star cast is the correct way to pass an address to percent p. It prints a long hexadecimal number, and that number changes on each run.
Now let us declare a pointer. Int star p means p is a pointer that can hold the address of an int. P equals ampersand marks stores the address of marks inside p. Star p, used in an expression, means go to that address and use the value there, and this is called dereferencing. The type must match, so an int pointer holds the address of an int, not a float.
Here p points to marks. The line star p equals ninety means, go to the address in p and store ninety there. That address belongs to marks, so marks itself becomes ninety. So printing marks and star p both give ninety. We changed marks without ever writing its name.
Students often mix up these two symbols. The star in a declaration, like int star p, makes p a pointer, while in an expression it means the value at the address. The ampersand in an expression means address of, and it is not used in a pointer declaration. Remember, ampersand gives an address, and star follows an address.
Pointers need care. A pointer that is declared but not given an address holds a garbage address. Using star on it may change random memory or crash the program. So if a pointer has no address yet, set it to NULL, which means points nowhere. And before using star p, check that p is not equal to NULL.
Pointers can do a little arithmetic, and it works in a special way. P plus one moves to the next element, not simply the next byte. For an int pointer, the address jumps by the size of an int, usually four bytes. P plus plus moves the pointer forward, and p minus minus moves it back. Subtracting two pointers into the same array tells you how many elements apart they are, but adding two pointers is not allowed.
Suppose an int array holding ten, twenty and thirty starts at address one thousand, and p points to it. P itself is address one thousand, and star p is ten. P plus one is address one thousand four, not one thousand one, and the value there is twenty. P plus two is one thousand eight, and the value is thirty.
Pause and predict the output. P starts at the first element, ten. After p plus plus, p points to the second element. So star p is twenty. Star of p plus one is the element after that, thirty. The output is twenty and thirty.
Arrays and pointers are close friends in C. The name of an array gives the address of its first element. In fact, a of i is just a short way to write star of a plus i. That is why int star p equals a needs no ampersand. But an array name is not a variable, so a plus plus gives a compiler error.
Here we walk through an array using only a pointer. P starts at a, the first element. While p is less than a plus four, which is just past the last element, we add star p to sum. Then p plus plus moves to the next element. Five plus ten plus fifteen plus twenty is fifty.
Pointers let a function change a variable in main. The function add GST receives the address of bill in a pointer called price. It adds eighteen percent to the value at that address. Five hundred plus ninety is five hundred ninety. Because we passed ampersand bill, bill in main really changes, which is call by reference.
Let us revise what we learned today. Every variable has an address, and the ampersand sign gives it. A pointer like int star p stores an address, and star p reads or changes the value there. P plus one jumps by the size of the type, not by one byte. For arrays, a of i is the same as star of a plus i. And pass ampersand x when a function must change x. Draw memory boxes on paper for every pointer program you trace.
Courses that teach this
| Course | Unit |
|---|---|
| Programming All levels C | Pointers and Dynamic Memory |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

