CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Cyber Safety and Ethics · 7 min · free

Pointers in C++

7 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

A C++ pointer stores an address: & gives the address, * gives the value there, new takes memory and delete frees it.

Follows the syllabus of: NIOS Senior Secondary Computer Science (330)

On screen in this lesson

Memory and addresses

RAM is a long row of numbered boxes
Each box number is an address
A variable lives at some address
& gives the address of a variable

What is a pointer?

A pointer stores the address of a variable
Declare: int *p;
Store an address: p = &marks;
* before p reads the value there

& and * together

ExpressionMeansValue here
marksthe value80
&marksits addresslike 0x7ffd
paddress storedsame as &marks
*pvalue at p80

Dynamic memory: new

Static memory: size fixed while compiling
new: takes memory while the program runs
int *p = new int;
int *a = new int[n];

Match new with delete

Taken withFree withExample
new intdeletedelete p;
new int[n]delete[]delete[] a;
forgot deletememory leakbug

The this pointer

Every member function gets a hidden pointer
this holds the address of the calling object
Use this->x when a parameter has the same name
Static functions do not get this

Quick answers

If int a = 5; int *p = &a; *p = *p + 10; what is a?

15, because *p is a itself.

How do you free new int[n]?

delete[].

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. Your friend asks where you live, and you give your house address, not the house. A pointer does the same for data. Today we learn addresses and pointers, new and delete, pointers to objects, the this pointer, and the pointer bugs that crash programs.

First, how memory works. RAM is like a long row of boxes, one after another. Each box has a number, called its address. When we declare a variable, it is stored at some address. The ampersand sign, placed before a variable, gives its address, and it is called the address of operator.

Now let us meet the pointer itself. A pointer is a variable that stores the address of another variable. We declare it with a star, like int star p, which means p can point to an int. Then p equals ampersand marks stores the address of marks in p. Writing star p gives the value stored at that address, and this star is called the dereference operator.

Let us see it work. Marks is seventy two. The pointer p stores the address of marks. Now star p equals eighty means, go to the address in p and store eighty there. That address belongs to marks. So marks has changed, and it prints eighty, even though we never wrote marks equals eighty.

Let us put these side by side. Marks gives the value, eighty. Ampersand marks gives its address, which is a hexadecimal number that changes each run. P holds that same address. Star p goes to that address, and gives eighty. Exams often ask you to predict these four.

Now, memory while the program runs. Normally, variable sizes are fixed when the program is compiled. Sometimes we know the size only at run time, like the number of students in a class. The new operator takes memory while the program runs, and gives back its address. New int gives space for one integer, and new int with n in square brackets gives an array of n integers.

Here n is three students, and m points to their marks. New int of n makes an array of three integers, filled with seventy, eighty five and ninety. We use m like a normal array, and the total prints two hundred forty five. Memory from new is not freed by itself. So we free it with delete, using square brackets because it was an array.

Always match new with the right delete. Memory from new int is freed with delete. Memory from new with square brackets is freed with delete square brackets. If we forget to delete, that memory stays taken until the program ends, and this bug is called a memory leak.

A pointer can also point to an object. New Acc creates a bank account object, and p stores its address. To reach a member through a pointer, we use the arrow operator, a minus sign and a greater than sign. P arrow bal is the same as star p in brackets, dot bal. We add one hundred, so it prints six hundred, and then we delete the object.

Inside a member function, how does the function know which object called it? Every non static member function receives a hidden pointer named this. The this pointer holds the address of the object that called the function. It is useful when a parameter has the same name as a data member. Static member functions belong to the class, not an object, so they have no this pointer.

Here the parameter and the data member are both named roll. Inside set, plain roll means the parameter. This arrow roll means the data member of the object. So this arrow roll equals roll copies twelve into the object s. Then main prints s dot roll, which is twelve.

Pointers are powerful, but mistakes can crash a program. A wild pointer is declared but never given an address, so it points anywhere. Dereferencing a null pointer, which points to nothing, usually crashes the program. A dangling pointer still holds an address after that memory was deleted. A memory leak happens when memory from new is never deleted. And deleting the same memory twice is also a serious bug.

Here are safe habits in one program. We take memory with new, holding forty five, and free it with delete. Then we set p to nullptr, the keyword for a pointer to nothing, so it cannot dangle. A pointer you cannot fill yet should also start as nullptr. Before using star p, check whether p is null. P is null here, so it prints Empty.

Pause and predict. A is five. The pointer p stores the address of a. Then star p equals star p plus ten. What is a now? The answer is fifteen, because star p is a itself.

Let us revise what we learned today. The ampersand gives an address, and the star gives the value at an address. New takes memory at run time, and delete gives it back. Use delete with square brackets for arrays. The arrow reaches members through a pointer, and this points to the calling object. Always start pointers as nullptr, and avoid wild, dangling and null pointer bugs.

Courses that teach this

CourseUnit
NIOS Senior Secondary Computer Science (330)Module 3: Programming in C++
Programming All levels CStructures, Unions, and Enums
Programming All levels C++Arrays, Strings and Pointers

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.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →