POINTERS in C++

The Cherno · 1.2M views · 2017 · 16:59

Open on YouTube

C, C++, Rust, Go & systems languagesEducation & learningtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering or asking about C++ pointer basics, treating it as a clear introduction to pointers as memory-address variables.

Recommended by 1 people across 1 different months, 2017 to 2020.

What it is

A 17-minute beginner tutorial from The Cherno's C++ series explaining what pointers are in C++: variables that hold memory addresses, how to take addresses, dereference, and use them. It is presented as a screen-based programming lesson by The Cherno.

What people said

Strong rec Resurrection · 2019-05 · Stack Overflow · on “Setting a variable equal to a variable that is equal to nullptr”

You misunderstood how pointers work. Pointers are variables like any other and their value is a memory address. Nothing more and nothing less. This line: Node* x = my_array[0]; Copies the address from my_array[0] to a new variable called x . While the address is the same, the x and my_array[0] are not the same thing. They are two distinct variables holding the same address. This line: my_array[0] = new Node; Re-assigns the address of my_array[0] to a new address of the heap allocated Node object. It overwrites the old address in my_array[0] and thus leaks the memory because the address (and the object in it) was never freed. However you still have it in x so you can still free it and prevent

Cites Ameer Ali · 2017-06 · Stack Overflow · on “How is a const char* not a just a character?”

I'm really confused about this because personally, I come from a java background, and recently began c++. So, I learnt all the basic stuff, like, printing stuff out to the screen and whatnot, and now, I learnt POINTERS. So, the person on youtube ( The Cherno's C++ Pointer tutorial [this video] This was not the video where he declared the const char*, just the pointer tutorial that I followed.) I've been following was using this following statement to declare what I know as a 'string'. const char* str = "random text here"; But, how is a char* converted into a string, and its even using the double quotation marks like a string! Also, what does a constant have to do with any of this? If I remove the

Cites Resurrection · 2019-04 · Stack Overflow · on “Copying a pointer, change what the copy is pointing to without changing original?”

First some clarification. Pointer is a standalone variable that holds a memory address. Nothing more, nothing less. The type of the poitner means that you, the programmer, told the compiler what is stored at that address so that you can retrieve the value stored at that address - this is called dereferencing. Now with that in mind you should be able to work out what you want to do yourself but let us walk through the process and we will use smart pointers because they help us manage the memory: std::unique_ptr<int> i = std::make_unique<int>(10); //Here we created a variable on the heap and gave it a value 10, //the address of it is stored in **i** std::unique_ptr<int> j = std::make_unique<in

Cites Abhyas29 · 2020-04 · Stack Overflow · on “How can I make variable change when another changes”

This can be accomplished using a pointer but if you are not already using it then I assume you are not familiar with the concept. So the first solution is without using a pointer. Solution 1 In this solution. a check is made before using the variable also_a to see if the value of a has changed. This is not automatic and thus might not qualify as solution. But this is the you get from me without using pointers. #include <stdio.h> void main(){ unsigned int a = 2; unsigned int also_a = a; unsigned int prev_a = a; unsigned int b = 1; a+=b; // also_a will be used. So check. if(prev_a != a) also_a = a; printf("\n%d %d\n", a, also_a); } Solution 2 I will use pointers. There will be one variable and